@extra-memoize/memory-cache 0.2.9 → 0.2.10
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/README.md +8 -0
- package/lib/es2015/caches/cache.d.ts +8 -0
- package/lib/es2015/caches/cache.js +28 -0
- package/lib/es2015/caches/cache.js.map +1 -0
- package/lib/es2015/caches/index.d.ts +1 -0
- package/lib/es2015/caches/index.js +1 -0
- package/lib/es2015/caches/index.js.map +1 -1
- package/lib/es2018/caches/cache.d.ts +8 -0
- package/lib/es2018/caches/cache.js +28 -0
- package/lib/es2018/caches/cache.js.map +1 -0
- package/lib/es2018/caches/index.d.ts +1 -0
- package/lib/es2018/caches/index.js +1 -0
- package/lib/es2018/caches/index.js.map +1 -1
- package/package.json +1 -1
- package/src/caches/cache.ts +25 -0
- package/src/caches/index.ts +2 -0
package/README.md
CHANGED
@@ -7,11 +7,19 @@ yarn add @extra-memoize/memory-cache
|
|
7
7
|
```
|
8
8
|
|
9
9
|
## API
|
10
|
+
### Cache
|
11
|
+
```ts
|
12
|
+
class Cache<T> implements ICache<T> {
|
13
|
+
clear(): void
|
14
|
+
}
|
15
|
+
```
|
16
|
+
|
10
17
|
### LRUCache
|
11
18
|
```ts
|
12
19
|
class LRUCache<T> implements ICache<T> {
|
13
20
|
constructor(limit: number)
|
14
21
|
|
22
|
+
delete(key: string): void
|
15
23
|
clear(): void
|
16
24
|
}
|
17
25
|
```
|
@@ -0,0 +1,28 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Cache = void 0;
|
4
|
+
const extra_memoize_1 = require("extra-memoize");
|
5
|
+
class Cache {
|
6
|
+
constructor() {
|
7
|
+
this.map = new Map();
|
8
|
+
}
|
9
|
+
set(key, value) {
|
10
|
+
this.map.set(key, value);
|
11
|
+
}
|
12
|
+
get(key) {
|
13
|
+
if (this.map.has(key)) {
|
14
|
+
return [extra_memoize_1.State.Hit, this.map.get(key)];
|
15
|
+
}
|
16
|
+
else {
|
17
|
+
return [extra_memoize_1.State.Miss];
|
18
|
+
}
|
19
|
+
}
|
20
|
+
delete(key) {
|
21
|
+
this.map.delete(key);
|
22
|
+
}
|
23
|
+
clear() {
|
24
|
+
this.map.clear();
|
25
|
+
}
|
26
|
+
}
|
27
|
+
exports.Cache = Cache;
|
28
|
+
//# sourceMappingURL=cache.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../src/caches/cache.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAE7C,MAAa,KAAK;IAAlB;QACU,QAAG,GAAG,IAAI,GAAG,EAAE,CAAA;IAqBzB,CAAC;IAnBC,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IAC1B,CAAC;IAED,GAAG,CAAC,GAAW;QACb,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACrB,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;SACtC;aAAM;YACL,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;SACpB;IACH,CAAC;IAED,MAAM,CAAC,GAAW;QAChB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACtB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;IAClB,CAAC;CACF;AAtBD,sBAsBC"}
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./cache"), exports);
|
17
18
|
__exportStar(require("./lru-cache"), exports);
|
18
19
|
__exportStar(require("./expirable-cache"), exports);
|
19
20
|
__exportStar(require("./expirable-cache-with-stale-while-revalidate"), exports);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/caches/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA2B;AAE3B,oDAAiC;AACjC,gFAA6D;AAC7D,wEAAqD;AACrD,mGAAgF;AAEhF,+CAA4B;AAC5B,2EAAwD;AACxD,mEAAgD;AAChD,8FAA2E"}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/caches/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AAEvB,8CAA2B;AAE3B,oDAAiC;AACjC,gFAA6D;AAC7D,wEAAqD;AACrD,mGAAgF;AAEhF,+CAA4B;AAC5B,2EAAwD;AACxD,mEAAgD;AAChD,8FAA2E"}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Cache = void 0;
|
4
|
+
const extra_memoize_1 = require("extra-memoize");
|
5
|
+
class Cache {
|
6
|
+
constructor() {
|
7
|
+
this.map = new Map();
|
8
|
+
}
|
9
|
+
set(key, value) {
|
10
|
+
this.map.set(key, value);
|
11
|
+
}
|
12
|
+
get(key) {
|
13
|
+
if (this.map.has(key)) {
|
14
|
+
return [extra_memoize_1.State.Hit, this.map.get(key)];
|
15
|
+
}
|
16
|
+
else {
|
17
|
+
return [extra_memoize_1.State.Miss];
|
18
|
+
}
|
19
|
+
}
|
20
|
+
delete(key) {
|
21
|
+
this.map.delete(key);
|
22
|
+
}
|
23
|
+
clear() {
|
24
|
+
this.map.clear();
|
25
|
+
}
|
26
|
+
}
|
27
|
+
exports.Cache = Cache;
|
28
|
+
//# sourceMappingURL=cache.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../src/caches/cache.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAE7C,MAAa,KAAK;IAAlB;QACU,QAAG,GAAG,IAAI,GAAG,EAAE,CAAA;IAqBzB,CAAC;IAnBC,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IAC1B,CAAC;IAED,GAAG,CAAC,GAAW;QACb,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACrB,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;SACtC;aAAM;YACL,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;SACpB;IACH,CAAC;IAED,MAAM,CAAC,GAAW;QAChB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACtB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;IAClB,CAAC;CACF;AAtBD,sBAsBC"}
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./cache"), exports);
|
17
18
|
__exportStar(require("./lru-cache"), exports);
|
18
19
|
__exportStar(require("./expirable-cache"), exports);
|
19
20
|
__exportStar(require("./expirable-cache-with-stale-while-revalidate"), exports);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/caches/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA2B;AAE3B,oDAAiC;AACjC,gFAA6D;AAC7D,wEAAqD;AACrD,mGAAgF;AAEhF,+CAA4B;AAC5B,2EAAwD;AACxD,mEAAgD;AAChD,8FAA2E"}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/caches/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AAEvB,8CAA2B;AAE3B,oDAAiC;AACjC,gFAA6D;AAC7D,wEAAqD;AACrD,mGAAgF;AAEhF,+CAA4B;AAC5B,2EAAwD;AACxD,mEAAgD;AAChD,8FAA2E"}
|
package/package.json
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
import { ICache, State } from 'extra-memoize'
|
2
|
+
|
3
|
+
export class Cache<T> implements ICache<T> {
|
4
|
+
private map = new Map()
|
5
|
+
|
6
|
+
set(key: string, value: T): void {
|
7
|
+
this.map.set(key, value)
|
8
|
+
}
|
9
|
+
|
10
|
+
get(key: string): [State.Miss] | [State.Hit, T] {
|
11
|
+
if (this.map.has(key)) {
|
12
|
+
return [State.Hit, this.map.get(key)]
|
13
|
+
} else {
|
14
|
+
return [State.Miss]
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
delete(key: string): void {
|
19
|
+
this.map.delete(key)
|
20
|
+
}
|
21
|
+
|
22
|
+
clear(): void {
|
23
|
+
this.map.clear()
|
24
|
+
}
|
25
|
+
}
|