Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

Commit

Permalink
RedisStore - Using direct Redis commands instead of hash Redis comman…
Browse files Browse the repository at this point in the history
…ds - #206 (#216)

Co-authored-by: Carl Ogren <rascarlito@gmail.com>
  • Loading branch information
arvind-bhaskar and lisathesecond committed Feb 3, 2021
1 parent 44d7227 commit aa0666f
Show file tree
Hide file tree
Showing 13 changed files with 690 additions and 12 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,36 @@ const api = setup({
const response = await api.get('/url')
```


#### Use Redis Default Store as Cache Store

You can give a `RedisDefaultStore` instance to `axios-cache-adapter` which will be used to store cache data in Redis using the default commands instead of hash commands.

_Note: This only works server-side_

```js
const { setup, RedisDefaultStore } = require('axios-cache-adapter')
const redis = require('redis')

const client = redis.createClient({
url: 'REDIS_URL',
})
const store = new RedisDefaultStore(client, {
prefix: 'namespace_as_prefix' // optional
})
const api = setup({
// `axios` options
baseURL: 'http://some-rest.api',
// `axios-cache-adapter` options
cache: {
maxAge: 15 * 60 * 1000,
store // Pass `RedisDefaultStore` store to `axios-cache-adapter`
}
})

const response = await api.get('/url')
```

### Check if response is served from network or from cache

When a response is served from cache a custom `response.request` object is created with a `fromCache` boolean.
Expand Down
9 changes: 9 additions & 0 deletions axios-cache-adapter.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ export declare function setupCache(options: IAxiosCacheAdapterOptions) : ISetupC

export class RedisStore { constructor(client: any, HASH_KEY?: string); }

export interface RedisDefaultOptions
{
prefix?: String;

maxScanCount?: number;
}

export class RedisDefaultStore { constructor(client: any, options?: RedisDefaultOptions); }

export interface IAxiosCacheAdapterRequest
{
/**
Expand Down
2 changes: 2 additions & 0 deletions dist/cache.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/cache.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/cache.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cache.min.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit aa0666f

Please sign in to comment.