2.2.1 • Published 3 years ago
@t.voslar/ts-cache-decorator v2.2.1
ts-cache-decorators
Install
npm i @t.voslar/ts-cache-decorator
Configuration
Choose one of the supported storages (MemcacheElastiCache or RedisStorage) or create your new storage which implements IStorage.
const cacheStorage = new MemcachedElastiCacheStorage('localhost:11211', {})
useStorage(cacheStorage)
Now you can use @Cache decorator
@Cache({ type: 'normal', cacheKey: 'getUser', ttl: 3 })
async getUser (userId: string): Promise<User> {
Above caching will take cacheKey + parameters (which is just userId in this case) and will create cache key, which will expire after 3 seconds.
If you need to filter some parameters you can use filterParams param.
@Cache({ type: 'normal', cacheKey: 'getUser', ttl: 3, filterParams: ['otherParam'] })
async getUser (userId: string, otherParam: boolean): Promise<User> {
Cache API
Param | Value | Description |
---|---|---|
type | 'normal' | Type of cache. |
cacheKey | string | Caching key. |
ttl | number | Time to live. |
filterParams | string[] | Parameters which should not be inside cache key. |
2.2.1
3 years ago
2.2.0
4 years ago
2.1.6
4 years ago
2.1.5
4 years ago
2.1.2
4 years ago
2.1.4
4 years ago
2.1.3
4 years ago
2.1.1
4 years ago
2.0.2
4 years ago
2.1.0
4 years ago
2.0.1
4 years ago
2.0.0
4 years ago
1.4.1
4 years ago
1.4.0
5 years ago
1.3.0
5 years ago
1.2.2
5 years ago
1.2.1
5 years ago
1.2.0
5 years ago
1.1.0
5 years ago
1.0.0
5 years ago