simple-in-memory-cache 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +7 -0
- package/dist/cache.d.ts +1 -0
- package/dist/cache.js +11 -1
- package/dist/cache.js.map +1 -1
- package/package.json +1 -1
package/changelog.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.3.0](https://www.github.com/ehmpathy/simple-in-memory-cache/compare/v0.2.1...v0.3.0) (2022-11-24)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **keys:** enable accurate retrieval of all valid cache keys ([5a70816](https://www.github.com/ehmpathy/simple-in-memory-cache/commit/5a708160850be4460f421ef39573ea54da17fbb2))
|
|
9
|
+
|
|
3
10
|
### [0.2.1](https://www.github.com/ehmpathy/simple-in-memory-cache/compare/v0.2.0...v0.2.1) (2022-11-23)
|
|
4
11
|
|
|
5
12
|
|
package/dist/cache.d.ts
CHANGED
package/dist/cache.js
CHANGED
|
@@ -7,6 +7,12 @@ exports.createCache = ({ defaultSecondsUntilExpiration = 5 * 60 } = {}) => {
|
|
|
7
7
|
const cache = {};
|
|
8
8
|
// define how to set an item into the cache
|
|
9
9
|
const set = (key, value, { secondsUntilExpiration = defaultSecondsUntilExpiration } = {}) => {
|
|
10
|
+
// handle cache invalidation
|
|
11
|
+
if (value === undefined) {
|
|
12
|
+
delete cache[key];
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
// handle setting
|
|
10
16
|
const expiresAtMse = getMseNow() + secondsUntilExpiration * 1000;
|
|
11
17
|
cache[key] = { value, expiresAtMse };
|
|
12
18
|
};
|
|
@@ -19,7 +25,11 @@ exports.createCache = ({ defaultSecondsUntilExpiration = 5 * 60 } = {}) => {
|
|
|
19
25
|
return undefined; // if already expired, then undefined
|
|
20
26
|
return cacheContent.value; // otherwise, its in the cache and not expired, so return the value
|
|
21
27
|
};
|
|
28
|
+
// define how to grab all valid keys
|
|
29
|
+
const keys = () => Object.entries(cache)
|
|
30
|
+
.filter(([_, value]) => value.expiresAtMse > getMseNow())
|
|
31
|
+
.map(([key]) => key);
|
|
22
32
|
// return the api
|
|
23
|
-
return { set, get };
|
|
33
|
+
return { set, get, keys };
|
|
24
34
|
};
|
|
25
35
|
//# sourceMappingURL=cache.js.map
|
package/dist/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":";;;AAUA,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;AAEhC,QAAA,WAAW,GAAG,CAAI,EAAE,6BAA6B,GAAG,CAAC,GAAG,EAAE,KAAiD,EAAE,EAExH,EAAE;IACF,4CAA4C;IAC5C,MAAM,KAAK,GAAgC,EAAE,CAAC;IAE9C,2CAA2C;IAC3C,MAAM,GAAG,GAAG,CACV,GAAW,EACX,KAAoB,EACpB,EAAE,sBAAsB,GAAG,6BAA6B,KAA0C,EAAE,EACpG,EAAE;QACF,4BAA4B;QAC5B,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;YAClB,OAAO;SACR;QAED,iBAAiB;QACjB,MAAM,YAAY,GAAG,SAAS,EAAE,GAAG,sBAAsB,GAAG,IAAI,CAAC;QACjE,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;IACvC,CAAC,CAAC;IAEF,2CAA2C;IAC3C,MAAM,GAAG,GAAG,CAAC,GAAW,EAAE,EAAE;QAC1B,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,CA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