Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating readme to show configuration options #644

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ await multiCache.mdel('foo', 'foo2');

See unit tests in [`test/multi-caching.test.ts`](./test/multi-caching.test.ts) for more information.

### 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.
* 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 false by default.

```typescript
import { caching } from 'cache-manager';

const memoryCache = await caching('memory', {
max: 100,
ttl: 10 * 1000 /*milliseconds*/,
shouldCloneBeforeSet: true, // this is set by false by default (optional)
});

### 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
Loading