1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | /**
|
8 | * The cache entry is a typed container of cache data used to track the
|
9 | * creation and expiration of cache entries.
|
10 | */
|
11 | class CacheEntry {
|
12 | /**
|
13 | * Initializes the cache entry.
|
14 | *
|
15 | * @param {*} value The cache entry value.
|
16 | * @param {number} ttl The time to live in milliseconds.
|
17 | */
|
18 | constructor(value, ttl) {
|
19 | /**
|
20 | * Cache entry value.
|
21 | *
|
22 | * @type {*}
|
23 | */
|
24 | this._value = value;
|
25 | /**
|
26 | * The time to live in milliseconds. The cache entry is considered
|
27 | * expired after this time.
|
28 | *
|
29 | * @type {number}
|
30 | */
|
31 |
|
32 | this._ttl = ttl;
|
33 | /**
|
34 | * The timestamp of creation of this cache entry.
|
35 | *
|
36 | * @type {number}
|
37 | */
|
38 |
|
39 | this._created = Date.now();
|
40 | }
|
41 | /**
|
42 | * Returns `true` if this entry has expired.
|
43 | *
|
44 | * @return {boolean} `true` if this entry has expired.
|
45 | */
|
46 |
|
47 |
|
48 | isExpired() {
|
49 | let now = Date.now();
|
50 | return now > this._created + this._ttl;
|
51 | }
|
52 | /**
|
53 | * Exports this cache entry into a JSON-serializable object.
|
54 | *
|
55 | * @return {{value: *, ttl: number}} This entry exported to a
|
56 | * JSON-serializable object.
|
57 | */
|
58 |
|
59 |
|
60 | serialize() {
|
61 | return {
|
62 | value: this._value,
|
63 | ttl: this._ttl
|
64 | };
|
65 | }
|
66 | /**
|
67 | * Returns the entry value.
|
68 | *
|
69 | * @return {*} The entry value.
|
70 | */
|
71 |
|
72 |
|
73 | getValue() {
|
74 | return this._value;
|
75 | }
|
76 |
|
77 | }
|
78 |
|
79 | exports.default = CacheEntry;
|
80 |
|
81 | typeof $IMA !== 'undefined' && $IMA !== null && $IMA.Loader && $IMA.Loader.register('ima/cache/CacheEntry', [], function (_export, _context) {
|
82 | ;
|
83 | return {
|
84 | setters: [],
|
85 | execute: function () {
|
86 | _export('default', exports.default);
|
87 | }
|
88 | };
|
89 | });
|