Skip to content

Commit

Permalink
fix docs (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
corradodellorusso authored Apr 21, 2024
1 parent 88a8460 commit 4a6dadb
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/cache-manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,11 @@ See unit tests in [`test/multi-caching.test.ts`](./test/multi-caching.test.ts) f

### Cache Manager Options

The `caching` and `multiCaching` functions accept an options object as the second parameter. The following options are available:
* max: The maximum number of items that can be stored in the cache. If the cache is full, the least recently used item is removed.
The `caching` function accepts an options object as the second parameter. The following options are available:
* ttl: The time to live in milliseconds. This is the maximum amount of time that an item can be in the cache before it is removed.
* shouldCloneBeforeSet: If true, the value will be cloned before being set in the cache. This is set to `true` by default.
* refreshThreshold: discussed in details below.
* isCacheable: a function to determine whether the value is cacheable or not.
* onBackgroundRefreshError: a function to handle errors that occur during background refresh.

```typescript
import { caching } from 'cache-manager';
Expand All @@ -185,6 +186,10 @@ const memoryCache = await caching('memory', {
});
```

When creating a memory store, you also get these addition options:
* max: The maximum number of items that can be stored in the cache. If the cache is full, the least recently used item is removed.
* shouldCloneBeforeSet: If true, the value will be cloned before being set in the cache. This is set to `true` by default.

### Refresh cache keys in background

Both the `caching` and `multicaching` modules support a mechanism to refresh expiring cache keys in background when using the `wrap` function.
Expand Down Expand Up @@ -219,14 +224,11 @@ When a value will be retrieved from Redis with a TTL minor than 3sec, the value

## Error Handling

Cache Manager now does not throw errors by default. Instead, all errors are evented through the `error` event. Here is an example on how to use it:
`multiCaching` now does not throw errors by default. Instead, all errors are evented through the `error` event. Here is an example on how to use it:

```javascript
const memoryCache = await caching('memory', {
max: 100,
ttl: 10 * 1000 /*milliseconds*/,
});
memoryCache.on('error', (error) => {
const multicache = await multiCaching([memoryCache, someOtherCache]);
multicache.on('error', (error) => {
console.error('Cache error:', error);
});
```
Expand Down

0 comments on commit 4a6dadb

Please sign in to comment.