@boredland/node-ts-cache 6.0.0 → 6.0.2
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 +1 -0
- package/dist/{cache-container/cache-container-types.d.ts → cacheContainer.d.ts} +16 -0
- package/dist/{cache-container/cache-container.js → cacheContainer.js} +0 -0
- package/dist/decorator.d.ts +8 -0
- package/dist/{decorator/cache-decorator.js → decorator.js} +6 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/storage.d.ts +23 -0
- package/dist/{cache-container/cache-container-types.js → storage.js} +0 -0
- package/dist/withCache.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cache-container/cache-container.d.ts +0 -17
- package/dist/cache-container/index.d.ts +0 -2
- package/dist/cache-container/index.js +0 -18
- package/dist/decorator/cache-decorator.d.ts +0 -2
- package/dist/decorator/index.d.ts +0 -1
- package/dist/decorator/index.js +0 -17
- package/dist/storage/index.d.ts +0 -1
- package/dist/storage/index.js +0 -17
- package/dist/storage/storage-types.d.ts +0 -7
- package/dist/storage/storage-types.js +0 -2
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ _Note: The underlying storage layer must be installed separately._
|
|
|
22
22
|
| [node-fs](https://www.npmjs.com/package/@boredland/node-ts-cache-storage-node-fs)| ```yarn add @boredland/node-ts-cache-storage-node-fs```|
|
|
23
23
|
| [ioredis](https://www.npmjs.com/package/@boredland/node-ts-cache-storage-ioredis)| ```yarn add @boredland/node-ts-cache-storage-ioredis```|
|
|
24
24
|
| [postgres](https://www.npmjs.com/package/@boredland/node-ts-cache-storage-pg)| ```yarn add @boredland/node-ts-cache-storage-pg```|
|
|
25
|
+
| [elasticsearch](https://www.npmjs.com/package/@boredland/node-ts-cache-storage-elasticsearch)| ```yarn add @boredland/node-ts-cache-storage-elasticsearch```|
|
|
25
26
|
|
|
26
27
|
## Usage
|
|
27
28
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Storage } from "./storage";
|
|
1
2
|
export declare type CachedItem<T = any> = {
|
|
2
3
|
content: T;
|
|
3
4
|
meta: {
|
|
@@ -23,3 +24,18 @@ export declare type CachingOptions = {
|
|
|
23
24
|
args: any[];
|
|
24
25
|
}) => string;
|
|
25
26
|
};
|
|
27
|
+
export declare class CacheContainer {
|
|
28
|
+
private storage;
|
|
29
|
+
constructor(storage: Storage);
|
|
30
|
+
getItem<T>(key: string): Promise<{
|
|
31
|
+
content: T;
|
|
32
|
+
meta: {
|
|
33
|
+
expired: boolean;
|
|
34
|
+
createdAt: number;
|
|
35
|
+
};
|
|
36
|
+
} | undefined>;
|
|
37
|
+
setItem(key: string, content: unknown, options?: Partial<CachingOptions>): Promise<void>;
|
|
38
|
+
clear(): Promise<void>;
|
|
39
|
+
private isItemExpired;
|
|
40
|
+
unsetKey(key: string): Promise<void>;
|
|
41
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CacheContainer, CachingOptions } from "./cacheContainer";
|
|
2
|
+
/**
|
|
3
|
+
* Decorator to be used on class methods to be cached
|
|
4
|
+
* @param container - container instance to be used for the method
|
|
5
|
+
* @param options - caching options to be used for the method
|
|
6
|
+
* @returns the return value of the method, cached or otherwise
|
|
7
|
+
*/
|
|
8
|
+
export declare function Cache(container: CacheContainer, options?: Partial<CachingOptions>): MethodDecorator;
|
|
@@ -9,6 +9,12 @@ const debug = (0, debug_1.default)("node-ts-cache");
|
|
|
9
9
|
const jsonCalculateKey = (data) => {
|
|
10
10
|
return `${data.className}:${data.methodName}:${JSON.stringify(data.args)}`;
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Decorator to be used on class methods to be cached
|
|
14
|
+
* @param container - container instance to be used for the method
|
|
15
|
+
* @param options - caching options to be used for the method
|
|
16
|
+
* @returns the return value of the method, cached or otherwise
|
|
17
|
+
*/
|
|
12
18
|
function Cache(container, options) {
|
|
13
19
|
return function (target, methodName,
|
|
14
20
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,5 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./decorator"), exports);
|
|
18
18
|
__exportStar(require("./storage"), exports);
|
|
19
|
-
__exportStar(require("./
|
|
19
|
+
__exportStar(require("./cacheContainer"), exports);
|
|
20
20
|
__exportStar(require("./withCache"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CachedItem } from ".";
|
|
2
|
+
export interface Storage {
|
|
3
|
+
/**
|
|
4
|
+
* returns a cached item from the storage layer
|
|
5
|
+
* @param key - key to look up
|
|
6
|
+
*/
|
|
7
|
+
getItem(key: string): Promise<CachedItem | undefined>;
|
|
8
|
+
/**
|
|
9
|
+
* sets a cached item on the storage layer
|
|
10
|
+
* @param key - key to store
|
|
11
|
+
* @param content - content to store, including some meta data
|
|
12
|
+
*/
|
|
13
|
+
setItem(key: string, content: CachedItem): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* removes item from the storage layer
|
|
16
|
+
* @param key - key to remove
|
|
17
|
+
*/
|
|
18
|
+
removeItem(key: string): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* remove all keys from the storage layer
|
|
21
|
+
*/
|
|
22
|
+
clear(): Promise<void>;
|
|
23
|
+
}
|
|
File without changes
|
package/dist/withCache.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CacheContainer, CachingOptions } from "./
|
|
1
|
+
import type { CacheContainer, CachingOptions } from "./cacheContainer";
|
|
2
2
|
declare type WithCacheOptions<Parameters> = Partial<Omit<CachingOptions, "calculateKey">> & {
|
|
3
3
|
/** an optional prefix to prepend to the key */
|
|
4
4
|
prefix?: string;
|
package/package.json
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Storage } from "../storage";
|
|
2
|
-
import type { CachingOptions } from "./cache-container-types";
|
|
3
|
-
export declare class CacheContainer {
|
|
4
|
-
private storage;
|
|
5
|
-
constructor(storage: Storage);
|
|
6
|
-
getItem<T>(key: string): Promise<{
|
|
7
|
-
content: T;
|
|
8
|
-
meta: {
|
|
9
|
-
expired: boolean;
|
|
10
|
-
createdAt: number;
|
|
11
|
-
};
|
|
12
|
-
} | undefined>;
|
|
13
|
-
setItem(key: string, content: unknown, options?: Partial<CachingOptions>): Promise<void>;
|
|
14
|
-
clear(): Promise<void>;
|
|
15
|
-
private isItemExpired;
|
|
16
|
-
unsetKey(key: string): Promise<void>;
|
|
17
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./cache-container"), exports);
|
|
18
|
-
__exportStar(require("./cache-container-types"), exports);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./cache-decorator";
|
package/dist/decorator/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./cache-decorator"), exports);
|
package/dist/storage/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./storage-types";
|
package/dist/storage/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./storage-types"), exports);
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { CachedItem } from "../cache-container";
|
|
2
|
-
export interface Storage {
|
|
3
|
-
getItem(key: string): Promise<CachedItem | undefined>;
|
|
4
|
-
setItem(key: string, content: CachedItem): Promise<void>;
|
|
5
|
-
removeItem(key: string): Promise<void>;
|
|
6
|
-
clear(): Promise<void>;
|
|
7
|
-
}
|