Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/e0ipso/cache-tags
Cache tags library for node.js
https://github.com/e0ipso/cache-tags
cache cacheability cacheability-metadata ioredis performance redis tags
Last synced: 9 days ago
JSON representation
Cache tags library for node.js
- Host: GitHub
- URL: https://github.com/e0ipso/cache-tags
- Owner: e0ipso
- License: mit
- Created: 2018-03-27T13:51:57.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T08:30:54.000Z (almost 2 years ago)
- Last Synced: 2024-10-25T08:15:13.448Z (12 days ago)
- Topics: cache, cacheability, cacheability-metadata, ioredis, performance, redis, tags
- Language: Ruby
- Size: 1.06 MB
- Stars: 9
- Watchers: 3
- Forks: 5
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Cache Tags
Adds cache tags for bulk invalidation.
Install
yarn add cache-tags
-
Install Redis normally. If you want to spin up
a local cluster for testing you can use:yarn create-cluster
andyarn destroy-cluster
.
Why?
If you need to invalidate cache entries that are related to each other, or just
list these cache entries that relate to each other you can use tags. You will
need to add the tags to the cache entries to be able to retrieve them later.
This module only supports Redis as the cache back-end at the moment. It is
tested against a single node and a cluster of 3 masters and 3 replicas.
Concept inspired by Drupal 8’s
cache tags. API and
implementation inspired by
Laravel’s Cache Tags.
Usage
If you want to see more usage examples, check the
functional tests.
This project uses ioredis as the Redis
client. All the options for that project are available here.
```js
const { TaggableCache: Redis } = require('cache-tags');
// Initialize the Redis client as you would using ioredis.
const redis = new Redis('127.0.0.1:6379');
// Now you can use `redis` as you would with ioredis, or you can enter tagged
// mode.
Promise.resolve()
// Use .tags to enter tagged mode, then call set or get.
.then(() =>
Promise.all([
redis.tags(['first-tag']).set('cache-entry-1', 'Lorem', 1234),
redis.tags(['first-tag', 'boring']).set('cache-entry-2', 'Ipsum', 2324),
])
)
.then(() =>
Promise.all([
// You can scope gets by enterign tagged mode.
redis.tags(['first-tag']).get('cache-entry-1'),
// Or you can get the item as you would do normally.
redis.get('cache-entry-2'),
])
)
.then(console.log) // ['Lorem', 'Ipsum'].
// You can also use tags to list items.
.then(() => redis.tags(['first-tag']).list())
.then(console.log) // ['Lorem', 'Ipsum'].
.then(() => redis.tags(['boring']).list())
.then(console.log) // ['Ipsum'].
// You can also use tags to invalidate items.
.then(() => redis.tags(['first-tag']).list())
.then(() =>
Promise.all([
redis.tags(['first-tag']).get('cache-entry-1'),
redis.get('cache-entry-2'),
])
)
.then(console.log); // []. Cache entries with tag 'first-tag' are gone.
```
Contributors
Contributors
Mateu Aguiló Bosch
Elliott Foster
License
cache-tags is MIT licensed.