UNPKG

@ima/core

Version:

IMA.js framework for isomorphic javascript application

50 lines (49 loc) 1.24 kB
/** * The cache entry is a typed container of cache data used to track the * creation and expiration of cache entries. */ export class CacheEntry { /** * Cache entry value. */ _value; /** * The time to live in milliseconds. The cache entry is considered * expired after this time. */ _ttl; /** * The timestamp of creation of this cache entry. */ _created = Date.now(); /** * Initializes the cache entry. * * @param value The cache entry value. * @param ttl The time to live in milliseconds. */ constructor(value, ttl){ this._value = value; this._ttl = ttl; } /** * Returns `true` if this entry has expired. * * @return `true` if this entry has expired. */ isExpired() { const now = Date.now(); return now > this._created + this._ttl; } /** * Exports this cache entry into a JSON-serializable object. * * This entry exported to a * JSON-serializable object. */ serialize() { return { value: this._value, ttl: this._ttl }; } /** * Returns the entry value. */ getValue() { return this._value; } } //# sourceMappingURL=CacheEntry.js.map