Comparing version 1.3.1 to 1.4.0
@@ -0,1 +1,8 @@ | ||
# [1.4.0](https://github.com/TinkoffCreditSystems/cachalot/compare/v1.3.1...v1.4.0) (2020-01-29) | ||
### Features | ||
* Tags can be stored separately in case the main redis instance uses eviction policy. ([c25ae76](https://github.com/TinkoffCreditSystems/cachalot/commit/c25ae76)) | ||
## [1.3.1](https://github.com/TinkoffCreditSystems/cachalot/compare/v1.3.0...v1.3.1) (2020-01-28) | ||
@@ -2,0 +9,0 @@ |
@@ -11,2 +11,3 @@ import { Executor, ValueOfExecutor } from './executor'; | ||
adapter: StorageAdapter; | ||
tagsAdapter?: StorageAdapter; | ||
} | ||
@@ -13,0 +14,0 @@ export interface ManagerConstructor<T extends BaseManager = any> { |
@@ -38,2 +38,3 @@ "use strict"; | ||
adapter: options.adapter, | ||
tagsAdapter: options.tagsAdapter, | ||
prefix: options.prefix, | ||
@@ -40,0 +41,0 @@ hashKeys: options.hashKeys |
@@ -7,2 +7,3 @@ import { ConnectionStatus } from '../connection-status'; | ||
adapter: StorageAdapter; | ||
tagsAdapter?: StorageAdapter; | ||
prefix?: string; | ||
@@ -53,2 +54,7 @@ hashKeys?: boolean; | ||
/** | ||
* Adapter for tags should be provided if your primary adapter uses eviction policy. | ||
* This adapter should not use any eviction policy. Records should be deleted only by demand or expiration. | ||
*/ | ||
private readonly tagsAdapter; | ||
/** | ||
* Gets a record using an adapter. It is expected that the adapter returns or null (value not found) | ||
@@ -55,0 +61,0 @@ * or serialized StorageRecord. |
@@ -23,2 +23,3 @@ "use strict"; | ||
constructor(options) { | ||
var _a; | ||
/** | ||
@@ -29,2 +30,3 @@ * An offline commands queue. | ||
this.adapter = options.adapter; | ||
this.tagsAdapter = (_a = options.tagsAdapter, (_a !== null && _a !== void 0 ? _a : options.adapter)); | ||
this.prefix = options.prefix || ''; | ||
@@ -53,3 +55,3 @@ this.hashKeys = options.hashKeys || false; | ||
const values = new Map(tags.map(tag => [this.createTagKey(tag.name), `${tag.version}`])); | ||
return this.adapter.mset(values); | ||
return this.tagsAdapter.mset(values); | ||
} | ||
@@ -91,3 +93,3 @@ /** | ||
async getTags(tagNames) { | ||
const existingTags = await this.adapter.mget(tagNames.map(tagName => this.createTagKey(tagName))); | ||
const existingTags = await this.tagsAdapter.mget(tagNames.map(tagName => this.createTagKey(tagName))); | ||
return tagNames.map((tagName, index) => ({ | ||
@@ -94,0 +96,0 @@ name: tagName, |
{ | ||
"name": "cachalot", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "Cache manager for nodejs with support different cache strategies", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -54,2 +54,21 @@ # Cachalot | ||
``` | ||
If your Redis instance uses eviction policy you need to use separate Redis instance for tags. **Tags should not be evicted!** | ||
```typescript | ||
// cache-with-tags.ts | ||
import Redis from 'ioredis'; | ||
import Cache, { RedisStorageAdapter } from 'cachalot'; | ||
import logger from './logger'; | ||
const redis = new Redis(); // with eviction policy enabled | ||
const redisForTags = new Redis(6380); | ||
export const cache = new Cache({ | ||
adapter: new RedisStorageAdapter(redis), | ||
tagsAdapter: new RedisStorageAdapter(redisForTags), | ||
logger, | ||
}); | ||
``` | ||
There are three main methods of working with Cache; their behavior depends on the chosen caching strategy: | ||
@@ -56,0 +75,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
119349
1655
225