Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions packages/cache-manager/test/wrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ describe('wrap', () => {

// 1st call should be cached
expect(await cache.wrap(data.key, async () => 1, config.ttl, config.refreshThreshold)).toEqual(1);
await sleep(501);
await sleep(510);
// Background refresh, but stale value returned
expect(await cache.wrap(data.key, async () => 2, config.ttl, config.refreshThreshold)).toEqual(1);
// New value in cache
expect(await cache.wrap(data.key, async () => 2, config.ttl, config.refreshThreshold)).toEqual(2);
await sleep(1001);
await sleep(1010);
// No background refresh with the new override params
expect(await cache.wrap(data.key, async () => 3, undefined, 500)).toEqual(2);
await sleep(500);
await sleep(510);
// Background refresh, but stale value returned
expect(await cache.wrap(data.key, async () => 4, undefined, 500)).toEqual(2);
expect(await cache.wrap(data.key, async () => 5, undefined, 500)).toEqual(4);
Expand Down
23 changes: 19 additions & 4 deletions packages/flat-cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,26 @@ cache.setKey('key', 'value');

This will save the data to disk every 5 minutes and will remove any data that has not been accessed in 1 hour or if the cache has more than 10,000 items. The `expirationInterval` will check every 5 minutes for expired items and evict them. This is replacement to the `save()` method with a `prune` option as it is no longer needed due to the fact that the in-memory cache handles pruning by `ttl` expiration or `lruSize` which will keep the most recent there.

here is an example doing load from already existing persisted cache
here is an example doing load from already existing persisted cache using the `createFromFile` function:

```javascript
import { load } from 'flat-cache';
const cache = load('cache1', './cacheAltDirectory');
import { createFromFile } from 'flat-cache';
const cache = createFromFile('./cacheAltDirectory/cache1');
```

You can also use the legacy load function to do this:

```javascript
import { FlatCache } from 'flat-cache';
const cache = new FlatCache();
cache.load('cache1', './cacheAltDirectory');
```
or

```javascript
import { FlatCache } from 'flat-cache';
const cache = new FlatCache({ cacheDir: './cacheAltDirectory' });
cache.load('cache1');
```

This will load the cache from the `./cacheAltDirectory` directory with the `cache1` id. If it doesnt exist it will not throw an error but will just return an empty cache.
Expand Down Expand Up @@ -190,4 +205,4 @@ This will use `JSON.parse` and `JSON.stringify` to parse and stringify the data.
You can contribute by forking the repo and submitting a pull request. Please make sure to add tests and update the documentation. To learn more about how to contribute go to our main README [https://github.com/jaredwray/cacheable](https://github.com/jaredwray/cacheable). This will talk about how to `Open a Pull Request`, `Ask a Question`, or `Post an Issue`.

# License and Copyright
[MIT © Jared Wray](./LICENSE)
[MIT © Jared Wray](./LICENSE)