UNPKG

@phensley/cldr-utils

Version:
32 lines 966 B
import { LRU } from './lru'; /** * Links an arrow function to an LRU cache. The function converts * a string to a value of type T. The string itself is used as * the cache key. * * Examples: * * Caching a number or date pattern. The cache key is the string * representation of the pattern. * * Caching any object that is expensive to create, where the cache * key identifies the type of object to cache. */ var Cache = /** @class */ (function () { function Cache(builder, capacity) { this.builder = builder; this.storage = new LRU(capacity); } Cache.prototype.size = function () { return this.storage.size(); }; Cache.prototype.get = function (raw) { var o = this.storage.get(raw); if (o === undefined) { o = this.builder(raw); this.storage.set(raw, o); } return o; }; return Cache; }()); export { Cache }; //# sourceMappingURL=cache.js.map