@celljs/cache 3.0.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/LICENSE +21 -0
- package/README.md +1 -0
- package/cell.yml +22 -0
- package/lib/node/cache-manager-factory.d.ts +10 -0
- package/lib/node/cache-manager-factory.d.ts.map +1 -0
- package/lib/node/cache-manager-factory.js +49 -0
- package/lib/node/cache-manager-factory.js.map +1 -0
- package/lib/node/cache-protocol.d.ts +21 -0
- package/lib/node/cache-protocol.d.ts.map +1 -0
- package/lib/node/cache-protocol.js +9 -0
- package/lib/node/cache-protocol.js.map +1 -0
- package/lib/node/cache-store-factory.d.ts +6 -0
- package/lib/node/cache-store-factory.d.ts.map +1 -0
- package/lib/node/cache-store-factory.js +68 -0
- package/lib/node/cache-store-factory.js.map +1 -0
- package/lib/node/delegating-cache-manager.d.ts +11 -0
- package/lib/node/delegating-cache-manager.d.ts.map +1 -0
- package/lib/node/delegating-cache-manager.js +25 -0
- package/lib/node/delegating-cache-manager.js.map +1 -0
- package/lib/node/index.d.ts +4 -0
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +20 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/module.d.ts +4 -0
- package/lib/node/module.d.ts.map +1 -0
- package/lib/node/module.js +42 -0
- package/lib/node/module.js.map +1 -0
- package/lib/package.spec.d.ts +1 -0
- package/lib/package.spec.d.ts.map +1 -0
- package/lib/package.spec.js +4 -0
- package/lib/package.spec.js.map +1 -0
- package/package.json +43 -0
- package/src/node/cache-manager-factory.ts +40 -0
- package/src/node/cache-protocol.ts +27 -0
- package/src/node/cache-store-factory.ts +59 -0
- package/src/node/delegating-cache-manager.ts +23 -0
- package/src/node/index.ts +3 -0
- package/src/node/module.ts +37 -0
- package/src/package.spec.ts +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Cellbang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Cell - Cache Component with cache-manager
|
package/cell.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
cell:
|
|
2
|
+
webpack:
|
|
3
|
+
filterWarningsPlugin:
|
|
4
|
+
cache:
|
|
5
|
+
- cache-manager-redis
|
|
6
|
+
- cache-manager-redis-yet
|
|
7
|
+
- cache-manager-redis-store
|
|
8
|
+
- cache-manager-ioredis
|
|
9
|
+
- cache-manager-ioredis-yet
|
|
10
|
+
- cache-manager-mongodb
|
|
11
|
+
- cache-manager-mongoose
|
|
12
|
+
- cache-manager-fs-binary
|
|
13
|
+
- cache-manager-fs-hash
|
|
14
|
+
- cache-manager-hazelcast
|
|
15
|
+
- cache-manager-memcached-store
|
|
16
|
+
- cache-manager-memory-store
|
|
17
|
+
cache:
|
|
18
|
+
config:
|
|
19
|
+
default:
|
|
20
|
+
store: memory
|
|
21
|
+
max: 100
|
|
22
|
+
ttl: 3600 # seconds
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CacheManager, CacheManagerFactory, CacheStoreFactory, CacheStoreFactoryConfig } from './cache-protocol';
|
|
2
|
+
export declare class DefaultCacheManagerFactory implements CacheManagerFactory {
|
|
3
|
+
protected readonly cacheConfig: {
|
|
4
|
+
[name: string]: CacheStoreFactoryConfig;
|
|
5
|
+
};
|
|
6
|
+
protected readonly cacheStoreFactory: CacheStoreFactory;
|
|
7
|
+
protected createMultiCacheManager(storesPromises: any[]): Promise<CacheManager>;
|
|
8
|
+
create(name?: string): CacheManager;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=cache-manager-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-manager-factory.d.ts","sourceRoot":"","sources":["../../src/node/cache-manager-factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAIjH,qBACa,0BAA2B,YAAW,mBAAmB;IAGlE,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,uBAAuB,CAAA;KAAE,CAAC;IAG5E,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;cAExC,uBAAuB,CAAC,cAAc,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC;IAMrF,MAAM,CAAC,IAAI,GAAE,MAAkB,GAAG,YAAY;CAmBjD"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DefaultCacheManagerFactory = void 0;
|
|
13
|
+
const cache_manager_1 = require("cache-manager");
|
|
14
|
+
const cache_protocol_1 = require("./cache-protocol");
|
|
15
|
+
const core_1 = require("@celljs/core");
|
|
16
|
+
const delegating_cache_manager_1 = require("./delegating-cache-manager");
|
|
17
|
+
let DefaultCacheManagerFactory = class DefaultCacheManagerFactory {
|
|
18
|
+
async createMultiCacheManager(storesPromises) {
|
|
19
|
+
const stores = await Promise.all(storesPromises);
|
|
20
|
+
const caches = await Promise.all(stores.map(s => (0, cache_manager_1.caching)(() => s)));
|
|
21
|
+
return new delegating_cache_manager_1.DelegatingCacheManager(Promise.resolve((0, cache_manager_1.multiCaching)(caches)));
|
|
22
|
+
}
|
|
23
|
+
create(name = 'default') {
|
|
24
|
+
const config = this.cacheConfig[name];
|
|
25
|
+
if (!config) {
|
|
26
|
+
throw Error('Not found cache options.');
|
|
27
|
+
}
|
|
28
|
+
const configs = Array.isArray(config) ? config : [config];
|
|
29
|
+
const stores = [];
|
|
30
|
+
for (const c of configs) {
|
|
31
|
+
stores.push(this.cacheStoreFactory.create(c));
|
|
32
|
+
}
|
|
33
|
+
const cachePromise = stores.length === 1 ? (0, cache_manager_1.caching)(() => stores[0]) : this.createMultiCacheManager(stores);
|
|
34
|
+
return new delegating_cache_manager_1.DelegatingCacheManager(cachePromise);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, core_1.Value)('cell.cache.config'),
|
|
39
|
+
__metadata("design:type", Object)
|
|
40
|
+
], DefaultCacheManagerFactory.prototype, "cacheConfig", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, core_1.Autowired)(cache_protocol_1.CacheStoreFactory),
|
|
43
|
+
__metadata("design:type", Object)
|
|
44
|
+
], DefaultCacheManagerFactory.prototype, "cacheStoreFactory", void 0);
|
|
45
|
+
DefaultCacheManagerFactory = __decorate([
|
|
46
|
+
(0, core_1.Component)(cache_protocol_1.CacheManagerFactory)
|
|
47
|
+
], DefaultCacheManagerFactory);
|
|
48
|
+
exports.DefaultCacheManagerFactory = DefaultCacheManagerFactory;
|
|
49
|
+
//# sourceMappingURL=cache-manager-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-manager-factory.js","sourceRoot":"","sources":["../../src/node/cache-manager-factory.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAAsD;AACtD,qDAAiH;AACjH,uCAA2D;AAC3D,yEAAoE;AAG7D,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IAQzB,KAAK,CAAC,uBAAuB,CAAC,cAAqB;QACzD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QACjD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAA,uBAAO,EAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACpE,OAAO,IAAI,iDAAsB,CAAC,OAAO,CAAC,OAAO,CAAC,IAAA,4BAAY,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7E,CAAC;IAED,MAAM,CAAC,OAAe,SAAS;QAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAEtC,IAAI,CAAC,MAAM,EAAE;YACT,MAAM,KAAK,CAAC,0BAA0B,CAAC,CAAC;SAC3C;QAED,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QAE1D,MAAM,MAAM,GAAU,EAAE,CAAC;QAEzB,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE;YACrB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;SAEjD;QACD,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAA,uBAAO,EAAM,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAChH,OAAO,IAAI,iDAAsB,CAAC,YAAY,CAAC,CAAC;IACpD,CAAC;CAEJ,CAAA;AA/BG;IAAC,IAAA,YAAK,EAAC,mBAAmB,CAAC;;+DACiD;AAE5E;IAAC,IAAA,gBAAS,EAAC,kCAAiB,CAAC;;qEAC2B;AAN/C,0BAA0B;IADtC,IAAA,gBAAS,EAAC,oCAAmB,CAAC;GAClB,0BAA0B,CAiCtC;AAjCY,gEAA0B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Cache, Store, CachingConfig as InnerCachingConfig } from 'cache-manager';
|
|
2
|
+
export declare const CacheManager: unique symbol;
|
|
3
|
+
export declare const CacheManagerFactory: unique symbol;
|
|
4
|
+
export declare const CacheStore: unique symbol;
|
|
5
|
+
export declare const CacheStoreFactory: unique symbol;
|
|
6
|
+
export declare type CachingConfig = InnerCachingConfig<any>;
|
|
7
|
+
export declare const DEFAULT_CACHE_MANAGER = "default";
|
|
8
|
+
export interface CacheManager extends Omit<Cache, 'store'> {
|
|
9
|
+
}
|
|
10
|
+
export interface CacheManagerFactory {
|
|
11
|
+
create(name?: string): CacheManager;
|
|
12
|
+
}
|
|
13
|
+
export interface CacheStore extends Store {
|
|
14
|
+
}
|
|
15
|
+
export declare type CacheStoreFactoryConfig = CachingConfig & {
|
|
16
|
+
store: string | Function | Object;
|
|
17
|
+
};
|
|
18
|
+
export interface CacheStoreFactory {
|
|
19
|
+
create<T>(config: CacheStoreFactoryConfig): Promise<CacheStore>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=cache-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-protocol.d.ts","sourceRoot":"","sources":["../../src/node/cache-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,IAAI,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAClF,eAAO,MAAM,YAAY,eAAyB,CAAC;AACnD,eAAO,MAAM,mBAAmB,eAAgC,CAAC;AACjE,eAAO,MAAM,UAAU,eAAuB,CAAC;AAC/C,eAAO,MAAM,iBAAiB,eAAgC,CAAC;AAE/D,oBAAY,aAAa,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;AAEpD,eAAO,MAAM,qBAAqB,YAAY,CAAC;AAE/C,MAAM,WAAW,YAAa,SAAQ,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC;CAAG;AAE7D,MAAM,WAAW,mBAAmB;IAChC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;CACvC;AAED,MAAM,WAAW,UAAW,SAAQ,KAAK;CAExC;AAED,oBAAY,uBAAuB,GAAG,aAAa,GAAG;IAClD,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;CACrC,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAC9B,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACnE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_CACHE_MANAGER = exports.CacheStoreFactory = exports.CacheStore = exports.CacheManagerFactory = exports.CacheManager = void 0;
|
|
4
|
+
exports.CacheManager = Symbol('CacheManager');
|
|
5
|
+
exports.CacheManagerFactory = Symbol('CacheManagerFactory');
|
|
6
|
+
exports.CacheStore = Symbol('CacheStore');
|
|
7
|
+
exports.CacheStoreFactory = Symbol('CacheManagerFactory');
|
|
8
|
+
exports.DEFAULT_CACHE_MANAGER = 'default';
|
|
9
|
+
//# sourceMappingURL=cache-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-protocol.js","sourceRoot":"","sources":["../../src/node/cache-protocol.ts"],"names":[],"mappings":";;;AACa,QAAA,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AACtC,QAAA,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AACpD,QAAA,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAClC,QAAA,iBAAiB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAIlD,QAAA,qBAAqB,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CacheStoreFactoryConfig, CacheStore, CacheStoreFactory } from './cache-protocol';
|
|
2
|
+
export declare class DefaultCacheStoreFactory implements CacheStoreFactory {
|
|
3
|
+
create(config: CacheStoreFactoryConfig): Promise<CacheStore>;
|
|
4
|
+
protected load(store: string): any;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=cache-store-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-store-factory.d.ts","sourceRoot":"","sources":["../../src/node/cache-store-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1F,qBACa,wBAAyB,YAAW,iBAAiB;IAExD,MAAM,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,UAAU,CAAC;IAgBlE,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM;CAoC/B"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.DefaultCacheStoreFactory = void 0;
|
|
10
|
+
const cache_protocol_1 = require("./cache-protocol");
|
|
11
|
+
const core_1 = require("@celljs/core");
|
|
12
|
+
let DefaultCacheStoreFactory = class DefaultCacheStoreFactory {
|
|
13
|
+
async create(config) {
|
|
14
|
+
if (typeof config.store === 'string') {
|
|
15
|
+
return this.load(config.store).create(config);
|
|
16
|
+
}
|
|
17
|
+
if (typeof config.store === 'object') {
|
|
18
|
+
if ('create' in config.store) {
|
|
19
|
+
return config.store.create(config);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return config.store;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
throw new Error('Not found cache store factory.');
|
|
26
|
+
}
|
|
27
|
+
load(store) {
|
|
28
|
+
// switch case to explicit require statements for webpack compatibility.
|
|
29
|
+
try {
|
|
30
|
+
switch (store) {
|
|
31
|
+
case 'memory':
|
|
32
|
+
return { create: require('cache-manager/dist/stores/memory.js').memoryStore };
|
|
33
|
+
case 'redis':
|
|
34
|
+
return require('cache-manager-redis');
|
|
35
|
+
case 'redis-store':
|
|
36
|
+
return { create: require('cache-manager-redis-store').redisStore };
|
|
37
|
+
case 'redis-yet':
|
|
38
|
+
return { create: require('cache-manager-redis-yet').redisStore };
|
|
39
|
+
case 'ioredis':
|
|
40
|
+
return require('cache-manager-ioredis');
|
|
41
|
+
case 'ioredis-yet':
|
|
42
|
+
return { create: require('cache-manager-ioredis-yet').redisStore };
|
|
43
|
+
case 'mongodb':
|
|
44
|
+
return require('cache-manager-mongodb');
|
|
45
|
+
case 'mongoose':
|
|
46
|
+
return require('cache-manager-mongoose');
|
|
47
|
+
case 'fs-binary':
|
|
48
|
+
return require('cache-manager-fs-binary');
|
|
49
|
+
case 'fs-hash':
|
|
50
|
+
return require('cache-manager-fs-hash');
|
|
51
|
+
case 'hazelcast':
|
|
52
|
+
return require('cache-manager-hazelcast');
|
|
53
|
+
case 'memcached-store':
|
|
54
|
+
return require('cache-manager-memcached-store');
|
|
55
|
+
case 'memory-store':
|
|
56
|
+
return require('cache-manager-memory-store');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
DefaultCacheStoreFactory = __decorate([
|
|
65
|
+
(0, core_1.Component)(cache_protocol_1.CacheStoreFactory)
|
|
66
|
+
], DefaultCacheStoreFactory);
|
|
67
|
+
exports.DefaultCacheStoreFactory = DefaultCacheStoreFactory;
|
|
68
|
+
//# sourceMappingURL=cache-store-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-store-factory.js","sourceRoot":"","sources":["../../src/node/cache-store-factory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,qDAA0F;AAC1F,uCAAyC;AAGlC,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAEjC,KAAK,CAAC,MAAM,CAAC,MAA+B;QAExC,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,EAAE;YAClC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SACjD;QAED,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,EAAE;YAClC,IAAI,QAAQ,IAAI,MAAM,CAAC,KAAK,EAAE;gBAC1B,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;aACtC;iBAAM;gBACH,OAAO,MAAM,CAAC,KAAK,CAAC;aACvB;SACJ;QACD,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACtD,CAAC;IAES,IAAI,CAAC,KAAa;QACxB,wEAAwE;QACxE,IAAI;YACA,QAAQ,KAAK,EAAE;gBACX,KAAK,QAAQ;oBACT,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,qCAAqC,CAAC,CAAC,WAAW,EAAE,CAAC;gBAClF,KAAK,OAAO;oBACR,OAAO,OAAO,CAAC,qBAAqB,CAAC,CAAC;gBAC1C,KAAK,aAAa;oBACd,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,2BAA2B,CAAC,CAAC,UAAU,EAAE,CAAC;gBACvE,KAAK,WAAW;oBACZ,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC,UAAU,EAAE,CAAC;gBACrE,KAAK,SAAS;oBACV,OAAO,OAAO,CAAC,uBAAuB,CAAC,CAAC;gBAC5C,KAAK,aAAa;oBACd,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,2BAA2B,CAAC,CAAC,UAAU,EAAE,CAAC;gBACvE,KAAK,SAAS;oBACV,OAAO,OAAO,CAAC,uBAAuB,CAAC,CAAC;gBAC5C,KAAK,UAAU;oBACX,OAAO,OAAO,CAAC,wBAAwB,CAAC,CAAC;gBAC7C,KAAK,WAAW;oBACZ,OAAO,OAAO,CAAC,yBAAyB,CAAC,CAAC;gBAC9C,KAAK,SAAS;oBACV,OAAO,OAAO,CAAC,uBAAuB,CAAC,CAAC;gBAC5C,KAAK,WAAW;oBACZ,OAAO,OAAO,CAAC,yBAAyB,CAAC,CAAC;gBAC9C,KAAK,iBAAiB;oBAClB,OAAO,OAAO,CAAC,+BAA+B,CAAC,CAAC;gBACpD,KAAK,cAAc;oBACf,OAAO,OAAO,CAAC,4BAA4B,CAAC,CAAC;aACpD;SACJ;QAAC,OAAO,KAAK,EAAE;YACZ,MAAM,KAAK,CAAC;SACf;IACL,CAAC;CAEJ,CAAA;AAtDY,wBAAwB;IADpC,IAAA,gBAAS,EAAC,kCAAiB,CAAC;GAChB,wBAAwB,CAsDpC;AAtDY,4DAAwB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CacheManager } from './cache-protocol';
|
|
2
|
+
export declare class DelegatingCacheManager implements CacheManager {
|
|
3
|
+
protected readonly delegate: Promise<CacheManager>;
|
|
4
|
+
constructor(delegate: Promise<CacheManager>);
|
|
5
|
+
set(key: string, value: unknown, ttl?: number | undefined): Promise<void>;
|
|
6
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
7
|
+
del(key: string): Promise<void>;
|
|
8
|
+
reset(): Promise<void>;
|
|
9
|
+
wrap<T>(key: string, fn: () => Promise<T>, ttl?: number | undefined): Promise<T>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=delegating-cache-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegating-cache-manager.d.ts","sourceRoot":"","sources":["../../src/node/delegating-cache-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,qBAAa,sBAAuB,YAAW,YAAY;IAE3C,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,YAAY,CAAC;gBAA/B,QAAQ,EAAE,OAAO,CAAC,YAAY,CAAC;IAExD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzE,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAG3C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAG/B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAGtB,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC;CAGzF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DelegatingCacheManager = void 0;
|
|
4
|
+
class DelegatingCacheManager {
|
|
5
|
+
constructor(delegate) {
|
|
6
|
+
this.delegate = delegate;
|
|
7
|
+
}
|
|
8
|
+
async set(key, value, ttl) {
|
|
9
|
+
return (await this.delegate).set(key, value, ttl);
|
|
10
|
+
}
|
|
11
|
+
async get(key) {
|
|
12
|
+
return (await this.delegate).get(key);
|
|
13
|
+
}
|
|
14
|
+
async del(key) {
|
|
15
|
+
return (await this.delegate).del(key);
|
|
16
|
+
}
|
|
17
|
+
async reset() {
|
|
18
|
+
return (await this.delegate).reset();
|
|
19
|
+
}
|
|
20
|
+
async wrap(key, fn, ttl) {
|
|
21
|
+
return (await this.delegate).wrap(key, fn, ttl);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.DelegatingCacheManager = DelegatingCacheManager;
|
|
25
|
+
//# sourceMappingURL=delegating-cache-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegating-cache-manager.js","sourceRoot":"","sources":["../../src/node/delegating-cache-manager.ts"],"names":[],"mappings":";;;AAEA,MAAa,sBAAsB;IAE/B,YAA+B,QAA+B;QAA/B,aAAQ,GAAR,QAAQ,CAAuB;IAAG,CAAC;IAElE,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAc,EAAE,GAAwB;QAC3D,OAAO,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,GAAG,CAAI,GAAW;QACpB,OAAO,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1C,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,GAAW;QACjB,OAAO,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1C,CAAC;IACD,KAAK,CAAC,KAAK;QACP,OAAO,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,CAAC;IACzC,CAAC;IACD,KAAK,CAAC,IAAI,CAAI,GAAW,EAAE,EAAoB,EAAE,GAAwB;QACrE,OAAO,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC;IACpD,CAAC;CACJ;AApBD,wDAoBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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-protocol"), exports);
|
|
18
|
+
__exportStar(require("./cache-manager-factory"), exports);
|
|
19
|
+
__exportStar(require("./cache-store-factory"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,0DAAwC;AACxC,wDAAsC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,CAAC;;AAIjB,wBA8BG"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@celljs/core");
|
|
4
|
+
const cache_protocol_1 = require("./cache-protocol");
|
|
5
|
+
require("./index");
|
|
6
|
+
const InnerCacheManager = Symbol('InnerCacheManager');
|
|
7
|
+
exports.default = (0, core_1.autoBind)(bind => {
|
|
8
|
+
bind(cache_protocol_1.CacheManager).toDynamicValue(ctx => {
|
|
9
|
+
var _a;
|
|
10
|
+
const name = (_a = ctx.currentRequest.target.getNamedTag()) === null || _a === void 0 ? void 0 : _a.value;
|
|
11
|
+
let cacheManager;
|
|
12
|
+
if (name) {
|
|
13
|
+
try {
|
|
14
|
+
cacheManager = ctx.container.getNamed(InnerCacheManager, name);
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
// ignore
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
try {
|
|
22
|
+
cacheManager = ctx.container.get(InnerCacheManager);
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
// ignore
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (cacheManager) {
|
|
29
|
+
return cacheManager;
|
|
30
|
+
}
|
|
31
|
+
const factory = ctx.container.get(cache_protocol_1.CacheManagerFactory);
|
|
32
|
+
cacheManager = factory.create(name);
|
|
33
|
+
if (name) {
|
|
34
|
+
ctx.container.bind(InnerCacheManager).toConstantValue(cacheManager).whenTargetNamed(name);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
ctx.container.bind(InnerCacheManager).toConstantValue(cacheManager);
|
|
38
|
+
}
|
|
39
|
+
return cacheManager;
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,qDAAqE;AACrE,mBAAiB;AAEjB,MAAM,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAEtD,kBAAe,IAAA,eAAQ,EAAC,IAAI,CAAC,EAAE;IAC3B,IAAI,CAAC,6BAAY,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;;QACpC,MAAM,IAAI,GAAG,MAAA,GAAG,CAAC,cAAc,CAAC,MAAM,CAAC,WAAW,EAAE,0CAAE,KAAK,CAAC;QAC5D,IAAI,YAAsC,CAAC;QAC3C,IAAI,IAAI,EAAE;YACN,IAAI;gBACA,YAAY,GAAG,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAe,iBAAiB,EAAE,IAAI,CAAC,CAAC;aAChF;YAAC,OAAO,CAAC,EAAE;gBACR,SAAS;aACZ;SACJ;aAAM;YACH,IAAI;gBACA,YAAY,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAAe,iBAAiB,CAAC,CAAC;aACrE;YAAC,OAAO,CAAC,EAAE;gBACR,SAAS;aACZ;SACJ;QACD,IAAI,YAAY,EAAE;YACd,OAAO,YAAY,CAAC;SACvB;QAED,MAAM,OAAO,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAAsB,oCAAmB,CAAC,CAAC;QAC5E,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,IAAI,EAAE;YACN,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;SAC7F;aAAM;YACH,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;SACvE;QACD,OAAO,YAAY,CAAC;IACxB,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=package.spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.spec.d.ts","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":"AAAA,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAE3B,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AACrD,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@celljs/cache",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "cache component for cache-manager",
|
|
5
|
+
"main": "lib/node/index.js",
|
|
6
|
+
"typings": "lib/node/index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@celljs/core": "3.0.0",
|
|
9
|
+
"cache-manager": "^5.2.3"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"cell-component"
|
|
16
|
+
],
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/cellbang/cell.git"
|
|
21
|
+
},
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/cellbang/cell/issues"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/cellbang/cell",
|
|
26
|
+
"files": [
|
|
27
|
+
"lib",
|
|
28
|
+
"src",
|
|
29
|
+
"cell.yml"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"lint": "cell-component lint",
|
|
33
|
+
"build": "cell-component build",
|
|
34
|
+
"watch": "cell-component watch",
|
|
35
|
+
"clean": "cell-component clean",
|
|
36
|
+
"test": "cell-component test:js"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@celljs/component": "3.0.0",
|
|
40
|
+
"@types/cache-manager": "^3.4.3"
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "c0ef8d269e33a795406bcbb240cac4b845c6c24c"
|
|
43
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { caching, multiCaching } from 'cache-manager';
|
|
2
|
+
import { CacheManager, CacheManagerFactory, CacheStoreFactory, CacheStoreFactoryConfig } from './cache-protocol';
|
|
3
|
+
import { Component, Value, Autowired } from '@celljs/core';
|
|
4
|
+
import { DelegatingCacheManager } from './delegating-cache-manager';
|
|
5
|
+
|
|
6
|
+
@Component(CacheManagerFactory)
|
|
7
|
+
export class DefaultCacheManagerFactory implements CacheManagerFactory {
|
|
8
|
+
|
|
9
|
+
@Value('cell.cache.config')
|
|
10
|
+
protected readonly cacheConfig: { [name: string]: CacheStoreFactoryConfig };
|
|
11
|
+
|
|
12
|
+
@Autowired(CacheStoreFactory)
|
|
13
|
+
protected readonly cacheStoreFactory: CacheStoreFactory;
|
|
14
|
+
|
|
15
|
+
protected async createMultiCacheManager(storesPromises: any[]): Promise<CacheManager> {
|
|
16
|
+
const stores = await Promise.all(storesPromises);
|
|
17
|
+
const caches = await Promise.all(stores.map(s => caching(() => s)));
|
|
18
|
+
return new DelegatingCacheManager(Promise.resolve(multiCaching(caches)));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
create(name: string = 'default'): CacheManager {
|
|
22
|
+
const config = this.cacheConfig[name];
|
|
23
|
+
|
|
24
|
+
if (!config) {
|
|
25
|
+
throw Error('Not found cache options.');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const configs = Array.isArray(config) ? config : [config];
|
|
29
|
+
|
|
30
|
+
const stores: any[] = [];
|
|
31
|
+
|
|
32
|
+
for (const c of configs) {
|
|
33
|
+
stores.push(this.cacheStoreFactory.create(c));
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
const cachePromise = stores.length === 1 ? caching<any>(() => stores[0]) : this.createMultiCacheManager(stores);
|
|
37
|
+
return new DelegatingCacheManager(cachePromise);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Cache, Store, CachingConfig as InnerCachingConfig } from 'cache-manager';
|
|
2
|
+
export const CacheManager = Symbol('CacheManager');
|
|
3
|
+
export const CacheManagerFactory = Symbol('CacheManagerFactory');
|
|
4
|
+
export const CacheStore = Symbol('CacheStore');
|
|
5
|
+
export const CacheStoreFactory = Symbol('CacheManagerFactory');
|
|
6
|
+
|
|
7
|
+
export type CachingConfig = InnerCachingConfig<any>;
|
|
8
|
+
|
|
9
|
+
export const DEFAULT_CACHE_MANAGER = 'default';
|
|
10
|
+
|
|
11
|
+
export interface CacheManager extends Omit<Cache, 'store'> {}
|
|
12
|
+
|
|
13
|
+
export interface CacheManagerFactory {
|
|
14
|
+
create(name?: string): CacheManager;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CacheStore extends Store {
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type CacheStoreFactoryConfig = CachingConfig & {
|
|
22
|
+
store: string | Function | Object;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export interface CacheStoreFactory {
|
|
26
|
+
create<T>(config: CacheStoreFactoryConfig): Promise<CacheStore>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { CacheStoreFactoryConfig, CacheStore, CacheStoreFactory } from './cache-protocol';
|
|
2
|
+
import { Component } from '@celljs/core';
|
|
3
|
+
|
|
4
|
+
@Component(CacheStoreFactory)
|
|
5
|
+
export class DefaultCacheStoreFactory implements CacheStoreFactory {
|
|
6
|
+
|
|
7
|
+
async create(config: CacheStoreFactoryConfig): Promise<CacheStore> {
|
|
8
|
+
|
|
9
|
+
if (typeof config.store === 'string') {
|
|
10
|
+
return this.load(config.store).create(config);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (typeof config.store === 'object') {
|
|
14
|
+
if ('create' in config.store) {
|
|
15
|
+
return config.store.create(config);
|
|
16
|
+
} else {
|
|
17
|
+
return config.store;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
throw new Error('Not found cache store factory.');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
protected load(store: string) {
|
|
24
|
+
// switch case to explicit require statements for webpack compatibility.
|
|
25
|
+
try {
|
|
26
|
+
switch (store) {
|
|
27
|
+
case 'memory':
|
|
28
|
+
return { create: require('cache-manager/dist/stores/memory.js').memoryStore };
|
|
29
|
+
case 'redis':
|
|
30
|
+
return require('cache-manager-redis');
|
|
31
|
+
case 'redis-store':
|
|
32
|
+
return { create: require('cache-manager-redis-store').redisStore };
|
|
33
|
+
case 'redis-yet':
|
|
34
|
+
return { create: require('cache-manager-redis-yet').redisStore };
|
|
35
|
+
case 'ioredis':
|
|
36
|
+
return require('cache-manager-ioredis');
|
|
37
|
+
case 'ioredis-yet':
|
|
38
|
+
return { create: require('cache-manager-ioredis-yet').redisStore };
|
|
39
|
+
case 'mongodb':
|
|
40
|
+
return require('cache-manager-mongodb');
|
|
41
|
+
case 'mongoose':
|
|
42
|
+
return require('cache-manager-mongoose');
|
|
43
|
+
case 'fs-binary':
|
|
44
|
+
return require('cache-manager-fs-binary');
|
|
45
|
+
case 'fs-hash':
|
|
46
|
+
return require('cache-manager-fs-hash');
|
|
47
|
+
case 'hazelcast':
|
|
48
|
+
return require('cache-manager-hazelcast');
|
|
49
|
+
case 'memcached-store':
|
|
50
|
+
return require('cache-manager-memcached-store');
|
|
51
|
+
case 'memory-store':
|
|
52
|
+
return require('cache-manager-memory-store');
|
|
53
|
+
}
|
|
54
|
+
} catch (error) {
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CacheManager } from './cache-protocol';
|
|
2
|
+
|
|
3
|
+
export class DelegatingCacheManager implements CacheManager {
|
|
4
|
+
|
|
5
|
+
constructor(protected readonly delegate: Promise<CacheManager>) {}
|
|
6
|
+
|
|
7
|
+
async set(key: string, value: unknown, ttl?: number | undefined): Promise<void> {
|
|
8
|
+
return (await this.delegate).set(key, value, ttl);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async get<T>(key: string): Promise<T | undefined> {
|
|
12
|
+
return (await this.delegate).get(key);
|
|
13
|
+
}
|
|
14
|
+
async del(key: string): Promise<void> {
|
|
15
|
+
return (await this.delegate).del(key);
|
|
16
|
+
}
|
|
17
|
+
async reset(): Promise<void> {
|
|
18
|
+
return (await this.delegate).reset();
|
|
19
|
+
}
|
|
20
|
+
async wrap<T>(key: string, fn: () => Promise<T>, ttl?: number | undefined): Promise<T> {
|
|
21
|
+
return (await this.delegate).wrap(key, fn, ttl);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { autoBind } from '@celljs/core';
|
|
2
|
+
import { CacheManager, CacheManagerFactory } from './cache-protocol';
|
|
3
|
+
import './index';
|
|
4
|
+
|
|
5
|
+
const InnerCacheManager = Symbol('InnerCacheManager');
|
|
6
|
+
|
|
7
|
+
export default autoBind(bind => {
|
|
8
|
+
bind(CacheManager).toDynamicValue(ctx => {
|
|
9
|
+
const name = ctx.currentRequest.target.getNamedTag()?.value;
|
|
10
|
+
let cacheManager: CacheManager | undefined;
|
|
11
|
+
if (name) {
|
|
12
|
+
try {
|
|
13
|
+
cacheManager = ctx.container.getNamed<CacheManager>(InnerCacheManager, name);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
// ignore
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
try {
|
|
19
|
+
cacheManager = ctx.container.get<CacheManager>(InnerCacheManager);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
// ignore
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (cacheManager) {
|
|
25
|
+
return cacheManager;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const factory = ctx.container.get<CacheManagerFactory>(CacheManagerFactory);
|
|
29
|
+
cacheManager = factory.create(name);
|
|
30
|
+
if (name) {
|
|
31
|
+
ctx.container.bind(InnerCacheManager).toConstantValue(cacheManager).whenTargetNamed(name);
|
|
32
|
+
} else {
|
|
33
|
+
ctx.container.bind(InnerCacheManager).toConstantValue(cacheManager);
|
|
34
|
+
}
|
|
35
|
+
return cacheManager;
|
|
36
|
+
});
|
|
37
|
+
});
|