simple-in-memory-cache 0.2.1 → 0.3.1

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/dist/cache.d.ts CHANGED
@@ -3,6 +3,7 @@ export interface SimpleInMemoryCache<T> {
3
3
  set: (key: string, value: T, options?: {
4
4
  secondsUntilExpiration?: number;
5
5
  }) => void;
6
+ keys: () => string[];
6
7
  }
7
8
  export interface SimpleInMemoryCacheState<T> {
8
9
  [index: string]: {
@@ -10,6 +11,16 @@ export interface SimpleInMemoryCacheState<T> {
10
11
  expiresAtMse: number;
11
12
  };
12
13
  }
13
- export declare const createCache: <T>({ defaultSecondsUntilExpiration }?: {
14
+ export declare const createCache: <T>({ seconds, defaultSecondsUntilExpiration: defaultSecondsUntilExpirationInput, }?: {
15
+ /**
16
+ * the number of seconds items in the cache expire after
17
+ */
14
18
  defaultSecondsUntilExpiration?: number | undefined;
19
+ /**
20
+ * a shorthand alias for `defaultSecondsUntilExpiration`
21
+ *
22
+ * note
23
+ * - if both options are set, `defaultSecondsUntilExpirationInput` takes precedence
24
+ */
25
+ seconds?: number | undefined;
15
26
  }) => SimpleInMemoryCache<T>;
package/dist/cache.js CHANGED
@@ -2,11 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createCache = void 0;
4
4
  const getMseNow = () => new Date().getTime();
5
- exports.createCache = ({ defaultSecondsUntilExpiration = 5 * 60 } = {}) => {
5
+ const createCache = ({ seconds, defaultSecondsUntilExpiration: defaultSecondsUntilExpirationInput, } = {}) => {
6
+ var _a;
7
+ // resolve input alias
8
+ const defaultSecondsUntilExpiration = (_a = defaultSecondsUntilExpirationInput !== null && defaultSecondsUntilExpirationInput !== void 0 ? defaultSecondsUntilExpirationInput : seconds) !== null && _a !== void 0 ? _a : 5 * 60;
6
9
  // initialize a fresh in-memory cache object
7
10
  const cache = {};
8
11
  // define how to set an item into the cache
9
- const set = (key, value, { secondsUntilExpiration = defaultSecondsUntilExpiration } = {}) => {
12
+ const set = (key, value, { secondsUntilExpiration = defaultSecondsUntilExpiration, } = {}) => {
13
+ // handle cache invalidation
14
+ if (value === undefined) {
15
+ delete cache[key];
16
+ return;
17
+ }
18
+ // handle setting
10
19
  const expiresAtMse = getMseNow() + secondsUntilExpiration * 1000;
11
20
  cache[key] = { value, expiresAtMse };
12
21
  };
@@ -19,7 +28,12 @@ exports.createCache = ({ defaultSecondsUntilExpiration = 5 * 60 } = {}) => {
19
28
  return undefined; // if already expired, then undefined
20
29
  return cacheContent.value; // otherwise, its in the cache and not expired, so return the value
21
30
  };
31
+ // define how to grab all valid keys
32
+ const keys = () => Object.entries(cache)
33
+ .filter(([_, value]) => value.expiresAtMse > getMseNow())
34
+ .map(([key]) => key);
22
35
  // return the api
23
- return { set, get };
36
+ return { set, get, keys };
24
37
  };
38
+ exports.createCache = createCache;
25
39
  //# 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":";;;AASA,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,CAAC,GAAW,EAAE,KAAQ,EAAE,EAAE,sBAAsB,GAAG,6BAA6B,KAA0C,EAAE,EAAE,EAAE;QAC1I,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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C,MAAM,GAAG,GAAG,CAAC,GAAW,EAAE,EAAE;QAC1B,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,CAAC,YAAY;YAAE,OAAO,SAAS,CAAC,CAAC,kCAAkC;QACvE,IAAI,YAAY,CAAC,YAAY,GAAG,SAAS,EAAE;YAAE,OAAO,SAAS,CAAC,CAAC,qCAAqC;QACpG,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,mEAAmE;IAChG,CAAC,CAAC;IAEF,oCAAoC;IACpC,MAAM,IAAI,GAAG,GAAG,EAAE,CAChB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;SAClB,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,YAAY,GAAG,SAAS,EAAE,CAAC;SACxD,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;IAEzB,iBAAiB;IACjB,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;AAC5B,CAAC,CAAC;AA3DW,QAAA,WAAW,eA2DtB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const cache_1 = require("./cache");
13
+ jest.setTimeout(30 * 1000); // give up to 60 seconds, since we deal with timeouts that we want to test on the ~15 second range
14
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
15
+ describe('cache', () => {
16
+ it('should be able to add an item to the cache', () => {
17
+ const { set } = (0, cache_1.createCache)();
18
+ set('meaning of life', 42);
19
+ });
20
+ it('should be able to get an item from the cache', () => {
21
+ const { set, get } = (0, cache_1.createCache)();
22
+ set('how many licks does it take to get to the center of a tootsie pop?', 3);
23
+ const licks = get('how many licks does it take to get to the center of a tootsie pop?');
24
+ expect(licks).toEqual(3);
25
+ });
26
+ it('should respect the default expiration for the cache', () => __awaiter(void 0, void 0, void 0, function* () {
27
+ const { set, get } = (0, cache_1.createCache)({ defaultSecondsUntilExpiration: 10 }); // we're gonna use this cache to keep track of the popcorn in the microwave - we should check more regularly since it changes quickly!
28
+ set('how popped is the popcorn?', 'not popped');
29
+ // prove that we recorded the value and its accessible immediately after setting
30
+ const popcornStatus = get('how popped is the popcorn?');
31
+ expect(popcornStatus).toEqual('not popped');
32
+ // prove that the value is still accessible after 9 seconds, since default ttl is 10 seconds
33
+ yield sleep(9 * 1000);
34
+ const popcornStatusAfter9Sec = get('how popped is the popcorn?');
35
+ expect(popcornStatusAfter9Sec).toEqual('not popped'); // still should say not popped
36
+ // and prove that after a total of 9 seconds, the status is no longer in the cache
37
+ yield sleep(1 * 1000); // sleep 1 more second
38
+ const popcornStatusAfter10Sec = get('how popped is the popcorn?');
39
+ expect(popcornStatusAfter10Sec).toEqual(undefined); // no longer defined, since the default seconds until expiration was 15
40
+ }));
41
+ it('should respect the default expiration for the cache set by shorthand alias', () => __awaiter(void 0, void 0, void 0, function* () {
42
+ const { set, get } = (0, cache_1.createCache)({ seconds: 10 }); // we're gonna use this cache to keep track of the popcorn in the microwave - we should check more regularly since it changes quickly!
43
+ set('how popped is the popcorn?', 'not popped');
44
+ // prove that we recorded the value and its accessible immediately after setting
45
+ const popcornStatus = get('how popped is the popcorn?');
46
+ expect(popcornStatus).toEqual('not popped');
47
+ // prove that the value is still accessible after 9 seconds, since default ttl is 10 seconds
48
+ yield sleep(9 * 1000);
49
+ const popcornStatusAfter9Sec = get('how popped is the popcorn?');
50
+ expect(popcornStatusAfter9Sec).toEqual('not popped'); // still should say not popped
51
+ // and prove that after a total of 9 seconds, the status is no longer in the cache
52
+ yield sleep(1 * 1000); // sleep 1 more second
53
+ const popcornStatusAfter10Sec = get('how popped is the popcorn?');
54
+ expect(popcornStatusAfter10Sec).toEqual(undefined); // no longer defined, since the default seconds until expiration was 15
55
+ }));
56
+ it('should respect the item level expiration for the cache', () => __awaiter(void 0, void 0, void 0, function* () {
57
+ const { set, get } = (0, cache_1.createCache)(); // remember, default expiration is greater than 1 min
58
+ set('ice cream state', 'solid', { secondsUntilExpiration: 5 }); // ice cream changes quickly in the heat! lets keep a quick eye on this
59
+ // prove that we recorded the value and its accessible immediately after setting
60
+ const iceCreamState = get('ice cream state');
61
+ expect(iceCreamState).toEqual('solid');
62
+ // prove that the value is still accessible after 4 seconds, since default ttl is 5 seconds
63
+ yield sleep(4 * 1000);
64
+ const iceCreamStateAfter4Sec = get('ice cream state');
65
+ expect(iceCreamStateAfter4Sec).toEqual('solid'); // still should say solid
66
+ // and prove that after a total of 5 seconds, the state is no longer in the cache
67
+ yield sleep(1 * 1000); // sleep 1 more second
68
+ const iceCreamStateAfter5Sec = get('ice cream state');
69
+ expect(iceCreamStateAfter5Sec).toEqual(undefined); // no longer defined, since the item level seconds until expiration was 5
70
+ }));
71
+ it('should accurately get keys', () => {
72
+ // create the cache
73
+ const { set, keys } = (0, cache_1.createCache)();
74
+ // check key is added when value is set
75
+ set('meaning-of-life', '42');
76
+ const keys1 = keys();
77
+ expect(keys1.length).toEqual(1);
78
+ expect(keys1[0]).toEqual('meaning-of-life');
79
+ // check that there are no duplicates when key value is updated
80
+ set('meaning-of-life', '42.0');
81
+ const keys2 = keys();
82
+ expect(keys2.length).toEqual(1);
83
+ expect(keys2[0]).toEqual('meaning-of-life');
84
+ // check that multiple keys can be set
85
+ set('purpose-of-life', 'propagation');
86
+ const keys3 = keys();
87
+ expect(keys3.length).toEqual(2);
88
+ expect(keys3[1]).toEqual('purpose-of-life');
89
+ // check that invalidation removes the key
90
+ set('meaning-of-life', undefined);
91
+ const keys4 = keys();
92
+ expect(keys4.length).toEqual(1);
93
+ expect(keys4[0]).toEqual('purpose-of-life');
94
+ });
95
+ });
96
+ //# sourceMappingURL=cache.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.test.js","sourceRoot":"","sources":["../src/cache.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mCAAsC;AAEtC,IAAI,CAAC,UAAU,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,kGAAkG;AAE9H,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAEhF,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACrB,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,EAAE,GAAG,EAAE,GAAG,IAAA,mBAAW,GAAE,CAAC;QAC9B,GAAG,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACtD,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAA,mBAAW,GAAE,CAAC;QACnC,GAAG,CACD,oEAAoE,EACpE,CAAC,CACF,CAAC;QACF,MAAM,KAAK,GAAG,GAAG,CACf,oEAAoE,CACrE,CAAC;QACF,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,qDAAqD,EAAE,GAAS,EAAE;QACnE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAA,mBAAW,EAAC,EA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5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCache = void 0;
3
4
  var cache_1 = require("./cache");
4
5
  Object.defineProperty(exports, "createCache", { enumerable: true, get: function () { return cache_1.createCache; } });
5
6
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,iCAA2D;AAAlD,oGAAA,WAAW,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iCAA2D;AAAlD,oGAAA,WAAW,OAAA"}
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "simple-in-memory-cache",
3
- "version": "0.2.1",
3
+ "author": "ehmpathy",
4
4
  "description": "A simple in-memory cache, for nodejs and the browser, with time based expiration policies.",
5
- "author": "UladKasach @uladkasach",
6
- "license": "MIT",
7
- "repository": "uladkasach/simple-in-memory-cache",
5
+ "version": "0.3.1",
6
+ "repository": "ehmpathy/simple-in-memory-cache",
8
7
  "homepage": "https://github.com/ehmpathy/simple-in-memory-cache",
9
8
  "keywords": [
10
9
  "cache",
@@ -29,36 +28,59 @@
29
28
  "/dist"
30
29
  ],
31
30
  "scripts": {
32
- "build:clean": "rm -rf ./dist",
33
31
  "build:ts": "tsc -p ./tsconfig.build.json",
34
- "build": "npm run build:clean && npm run build:ts",
35
- "test:types": "tsc --noEmit",
36
- "test:format": "prettier --parser typescript --check 'src/**/*.ts' --config ./prettier.config.js",
37
- "test:lint": "eslint -c ./.eslintrc.js src/**/*.ts",
38
- "test:unit": "jest --forceExit --verbose --passWithNoTests",
39
- "test:integration": "jest -c ./jest.integration.config.js --forceExit --verbose --passWithNoTests",
40
- "test": "npm run test:types && npm run test:lint && npm run test:unit && npm run test:integration",
32
+ "commit:with-cli": "npx cz",
33
+ "fix:format:prettier": "prettier --write '**/*.ts' --config ./prettier.config.js",
34
+ "fix:format": "npm run fix:format:prettier",
35
+ "fix:lint": "eslint -c ./.eslintrc.js src/**/*.ts --fix",
36
+ "build:clean": "rm dist/ -rf",
37
+ "build:compile": "tsc -p ./tsconfig.build.json",
38
+ "build": "npm run build:clean && npm run build:compile",
39
+ "test:commits": "LAST_TAG=$(git describe --tags --abbrev=0 @^ 2> /dev/null || git rev-list --max-parents=0 HEAD) && npx commitlint --from $LAST_TAG --to HEAD --verbose",
40
+ "test:types": "tsc -p ./tsconfig.build.json --noEmit",
41
+ "test:format:prettier": "prettier --parser typescript --check 'src/**/*.ts' --config ./prettier.config.js",
42
+ "test:format": "npm run test:format:prettier",
43
+ "test:lint:deps": "npx depcheck -c ./depcheckrc.yml",
44
+ "test:lint:eslint": "eslint -c ./.eslintrc.js src/**/*.ts",
45
+ "test:lint": "npm run test:lint:eslint && npm run test:lint:deps",
46
+ "test:unit": "jest -c ./jest.unit.config.ts --forceExit --verbose --passWithNoTests",
47
+ "test:integration": "jest -c ./jest.integration.config.ts --forceExit --verbose --passWithNoTests",
48
+ "test:acceptance:locally": "npm run build && LOCALLY=true jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests",
49
+ "test": "npm run test:commits && npm run test:types && npm run test:format && npm run test:lint && npm run test:unit && npm run test:integration && npm run test:acceptance:locally",
50
+ "test:acceptance": "npm run build && jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests",
51
+ "prepush": "npm run test && npm run build",
41
52
  "prepublish": "npm run build",
42
- "preversion": "npm run prepublish && npm run test",
43
- "postversion": "git push origin master --tags --no-verify"
53
+ "preversion": "npm run prepush",
54
+ "postversion": "git push origin HEAD --tags --no-verify"
44
55
  },
45
56
  "devDependencies": {
46
- "@types/jest": "^24.0.18",
47
- "@types/uuid": "^3.4.5",
48
- "@typescript-eslint/eslint-plugin": "2.19.0",
49
- "@typescript-eslint/parser": "2.19.0",
50
- "eslint": "6.1.0",
51
- "eslint-config-airbnb-base": "14.0.0",
52
- "eslint-config-airbnb-typescript": "7.0.0",
53
- "eslint-config-prettier": "6.10.0",
54
- "eslint-plugin-import": "2.20.1",
55
- "eslint-plugin-prettier": "3.1.2",
56
- "husky": "^1.3.1",
57
- "jest": "^25.5.4",
58
- "prettier": "^2.0.4",
59
- "ts-jest": "^25.4.0",
60
- "typescript": "^3.8.3",
61
- "uuid": "^3.3.3"
57
+ "@commitlint/config-conventional": "13.1.0",
58
+ "@trivago/prettier-plugin-sort-imports": "2.0.4",
59
+ "@tsconfig/node-lts-strictest": "18.12.1",
60
+ "@types/jest": "29.2.4",
61
+ "@typescript-eslint/eslint-plugin": "5.46.1",
62
+ "@typescript-eslint/parser": "5.46.1",
63
+ "commitlint": "^17.6.7",
64
+ "core-js": "3.26.1",
65
+ "cz-conventional-changelog": "3.3.0",
66
+ "declapract": "^0.11.2",
67
+ "declapract-typescript-ehmpathy": "^0.25.1",
68
+ "depcheck": "1.4.3",
69
+ "eslint": "8.30.0",
70
+ "eslint-config-airbnb-typescript": "17.0.0",
71
+ "eslint-config-prettier": "8.5.0",
72
+ "eslint-plugin-import": "2.26.0",
73
+ "eslint-plugin-prettier": "4.2.1",
74
+ "husky": "7.0.2",
75
+ "jest": "29.3.1",
76
+ "prettier": "2.8.1",
77
+ "ts-jest": "29.0.3",
78
+ "ts-node": "10.9.1",
79
+ "typescript": "4.9.4"
62
80
  },
63
- "dependencies": {}
81
+ "config": {
82
+ "commitizen": {
83
+ "path": "./node_modules/cz-conventional-changelog"
84
+ }
85
+ }
64
86
  }
@@ -1,7 +1,7 @@
1
1
  # simple-in-memory-cache
2
2
 
3
- ![ci_on_commit](https://github.com/ehmpathy/simple-in-memory-cache/workflows/ci_on_commit/badge.svg)
4
- ![deploy_on_tag](https://github.com/ehmpathy/simple-in-memory-cache/workflows/deploy_on_tag/badge.svg)
3
+ ![test](https://github.com/ehmpathy/simple-in-memory-cache/workflows/test/badge.svg)
4
+ ![publish](https://github.com/ehmpathy/simple-in-memory-cache/workflows/publish/badge.svg)
5
5
 
6
6
  A simple in-memory cache, for nodejs and the browser, with time based expiration policies.
7
7
 
package/changelog.md DELETED
@@ -1,21 +0,0 @@
1
- # Changelog
2
-
3
- ### [0.2.1](https://www.github.com/ehmpathy/simple-in-memory-cache/compare/v0.2.0...v0.2.1) (2022-11-23)
4
-
5
-
6
- ### Bug Fixes
7
-
8
- * **cicd:** add test:format script to unblock ghactions ([f4f645c](https://www.github.com/ehmpathy/simple-in-memory-cache/commit/f4f645ce6ec9d44ea44a2f175f5fbcdddbacd45f))
9
-
10
- ## [0.2.0](https://www.github.com/ehmpathy/simple-in-memory-cache/compare/v0.1.0...v0.2.0) (2022-11-23)
11
-
12
-
13
- ### Features
14
-
15
- * **cicd:** add please release github cicd ([43f27ea](https://www.github.com/ehmpathy/simple-in-memory-cache/commit/43f27ea69477e5e3966b2eec3289f2f4d0d99dca))
16
-
17
-
18
- ### Bug Fixes
19
-
20
- * **remote:** replace references from uladkasach repo to ehmpathy repo ([983e8ac](https://www.github.com/ehmpathy/simple-in-memory-cache/commit/983e8ac3ae9eeb68cc6d63505d6c8ed851f69d57))
21
- * **types:** expose a type for an instance of the cache ([1bcbf9b](https://www.github.com/ehmpathy/simple-in-memory-cache/commit/1bcbf9b9aa38934ce08f86e628938681d1dfd2ee))