cacheable 1.10.1 → 1.10.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 +24 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
* [TTL Propagation and Storage Tiering](#ttl-propagation-and-storage-tiering)
|
|
33
33
|
* [Shorthand for Time to Live (ttl)](#shorthand-for-time-to-live-ttl)
|
|
34
34
|
* [Non-Blocking Operations](#non-blocking-operations)
|
|
35
|
+
* [Non-Blocking with @keyv/redis](#non-blocking-with-keyvredis)
|
|
35
36
|
* [CacheSync - Distributed Updates](#cachesync---distributed-updates)
|
|
36
37
|
* [Cacheable Options](#cacheable-options)
|
|
37
38
|
* [Cacheable Statistics (Instance Only)](#cacheable-statistics-instance-only)
|
|
@@ -256,6 +257,29 @@ raws.forEach((entry, idx) => {
|
|
|
256
257
|
|
|
257
258
|
If you want your layer 2 (secondary) store to be non-blocking you can set the `nonBlocking` property to `true` in the options. This will make the secondary store non-blocking and will not wait for the secondary store to respond on `setting data`, `deleting data`, or `clearing data`. This is useful if you want to have a faster response time and not wait for the secondary store to respond.
|
|
258
259
|
|
|
260
|
+
# Non-Blocking with @keyv/redis
|
|
261
|
+
|
|
262
|
+
`@keyv/redis` is one of the most popular storage adapters used with `cacheable`. It provides a Redis-backed cache store that can be used as a secondary store. It is a bit complicated to setup as by default it causes hangs and blocking with its default configuration. To get past this you will need to configure the following:
|
|
263
|
+
|
|
264
|
+
Construct your own Redis client via the `createClient()` method from `@keyv/redis` with the following options:
|
|
265
|
+
* Set `disableOfflineQueue` to `true`
|
|
266
|
+
* Set `socket.reconnectStrategy` to `false`
|
|
267
|
+
In the KeyvRedis options:
|
|
268
|
+
* Set `throwOnConnectError` to `false`
|
|
269
|
+
In the Cacheable options:
|
|
270
|
+
* Set `nonBlocking` to `true`
|
|
271
|
+
|
|
272
|
+
We have also build a function to help with this called `createKeyvNonBlocking` inside the `@keyv/redis` package after version `4.6.0`. Here is an example of how to use it:
|
|
273
|
+
|
|
274
|
+
```javascript
|
|
275
|
+
import { Cacheable } from 'cacheable';
|
|
276
|
+
import { createKeyvNonBlocking } from '@keyv/redis';
|
|
277
|
+
|
|
278
|
+
const secondary = createKeyvNonBlocking('redis://user:pass@localhost:6379');
|
|
279
|
+
|
|
280
|
+
const cache = new Cacheable({ secondary, nonBlocking: true });
|
|
281
|
+
```
|
|
282
|
+
|
|
259
283
|
# GetOrSet
|
|
260
284
|
|
|
261
285
|
The `getOrSet` method provides a convenient way to implement the cache-aside pattern. It attempts to retrieve a value
|