mirror of
https://github.com/arthurfiorette/axios-cache-interceptor.git
synced 2025-12-08 17:36:16 +00:00
docs: add an example node-cache implementation in docs (#841)
* docs: added example for node-cache in storages.md * docs: refactor node-cache example for conciseness Co-authored-by: Arthur Fiorette <47537704+arthurfiorette@users.noreply.github.com> * docs: fix syntax errors in node-cache example * docs: remove unneeded import in node-cache example --------- Co-authored-by: Arthur Fiorette <47537704+arthurfiorette@users.noreply.github.com>
This commit is contained in:
parent
a04ce0616f
commit
77a8f7a8bf
@ -147,6 +147,7 @@ storages, you can use them as a base to also create your own.
|
||||
|
||||
- [Node Redis v4](#node-redis-storage)
|
||||
- [IndexedDb](#indexeddb)
|
||||
- [Node Cache](#node-cache)
|
||||
- **Have another one?**
|
||||
- [Open a PR](https://github.com/arthurfiorette/axios-cache-interceptor/pulls) to add it
|
||||
here.
|
||||
@ -233,3 +234,30 @@ const indexedDbStorage = buildStorage({
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Node Cache
|
||||
|
||||
This example implementation uses [node-cache](https://github.com/node-cache/node-cache) as a storage method. Do note
|
||||
that this library is somewhat old, however it appears to work at the time of writing.
|
||||
|
||||
```ts
|
||||
import { buildStorage } from "axios-cache-interceptor";
|
||||
import NodeCache from "node-cache";
|
||||
|
||||
const cache = new NodeCache({ stdTTL: 60 * 60 * 24 * 7 });
|
||||
|
||||
const cacheStorage = buildStorage({
|
||||
find(key) {
|
||||
return cache.get(key)
|
||||
}
|
||||
|
||||
set(key, value) {
|
||||
cache.set(key, value);
|
||||
},
|
||||
|
||||
remove(key) {
|
||||
cache.del(key);
|
||||
},
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user