Skip to content

Commit

Permalink
doc: cache.invalidateAll
Browse files Browse the repository at this point in the history
  • Loading branch information
Simone Sanfratello committed Feb 24, 2022
1 parent 7aa0ae6 commit a52c825
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,42 @@ If `arg` is specified, only the elements cached with the given `name` and `arg`

### `cache.invalidateAll(references, [storage])`

TODO
`cache.invalidateAll` perform invalidation over the whole storage; if `storage` is not specified - using the same `name` as the defined function, invalidation is made over the default storage.

references can be:
`references` can be:

- a single reference
- an array of references (without wildcard)
- a matching reference with wildcard, same logic for `memory` and `redis`
* a single reference
* an array of references (without wildcard)
* a matching reference with wildcard, same logic for `memory` and `redis`

Exmple

```js
const cache = createCache({ ttl: 60 })

cache.define('fetchUser', {
references: (args, key, result) => result ? [`user:${result.id}`] : null
}, (id) => database.find({ table: 'users', where: { id }}))

cache.define('fetchCountries', {
storage: { type: 'memory', size: 256 },
references: (args, key, result) => [`countries`]
}, (id) => database.find({ table: 'countries' }))

// ...

// invalidate all users from default storage
cache.invalidateAll('user:*')

// invalidate user 1 from default storage
cache.invalidateAll('user:1')

// invalidate user 1 and user 2 from default storage
cache.invalidateAll(['user:1', 'user:2'])

// note "fetchCountries" uses a different storage
cache.invalidateAll('countries', 'fetchCountries')
```

See below how invalidation and references work.

Expand Down

0 comments on commit a52c825

Please sign in to comment.