UNPKG

@phensley/cldr-core

Version:
34 lines 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var lru_1 = require("./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_1.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; }()); exports.Cache = Cache; //# sourceMappingURL=cache.js.map