UNPKG

@ima/core

Version:

IMA.js framework for isomorphic javascript application

57 lines (56 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "CacheEntry", { enumerable: true, get: function() { return CacheEntry; } }); 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