| 187 | |
| 188 | /** @type {MakeCacheableWithContextResult & { bindCache: BindCacheForContext, bindContextCache: BindContextCacheForContext }} */ |
| 189 | const cachedFn = (context, identifier, associatedObjectForCache) => { |
| 190 | if (!associatedObjectForCache) return fn(context, identifier); |
| 191 | |
| 192 | let innerCache = cache.get(associatedObjectForCache); |
| 193 | if (innerCache === undefined) { |
| 194 | innerCache = new Map(); |
| 195 | cache.set(associatedObjectForCache, innerCache); |
| 196 | } |
| 197 | |
| 198 | /** @type {undefined | string} */ |
| 199 | let cachedResult; |
| 200 | let innerSubCache = innerCache.get(context); |
| 201 | if (innerSubCache === undefined) { |
| 202 | innerCache.set(context, (innerSubCache = new Map())); |
| 203 | } else { |
| 204 | cachedResult = innerSubCache.get(identifier); |
| 205 | } |
| 206 | |
| 207 | if (cachedResult !== undefined) { |
| 208 | return cachedResult; |
| 209 | } |
| 210 | const result = fn(context, identifier); |
| 211 | innerSubCache.set(identifier, result); |
| 212 | return result; |
| 213 | }; |
| 214 | |
| 215 | /** @type {BindCacheForContext} */ |
| 216 | cachedFn.bindCache = (associatedObjectForCache) => { |