Skip to content

Repository files navigation

Coverage StatusDownloadsnpm versiondependenciesbuildLicense

RediBox Cache

Cache any data quickly and easily in Redis. Caching data is important to most applications. This hook handles various common requirements for caching data, specifically in Redis.

Installation

First ensure you have RediBox installed.

Install Schedule via npm:

npm install redibox-hook-cache --save

Usage

Configure cache

This hook will still work without setting any configuration options.

Within your redibox config, we'll setup a new cache object containing our configiration options:

  • enabled [Boolean]
    • default: true If disabled will by-pass any cached data.
  • defaultTTL [Number]
    • default: 60 In seconds, if no time to live (TTL) is specified, this is how long items to live in the cache for.
  • keyPrefix [String]
    • default: cache The namespace to store the cached items in Redis under. Shouldn't usually need changing.

Basic API

GET
// Get data by key from the cacheRediBox.hooks.cache.get('cat').then(data=>{console.log('Got a cat from cache',data);});
SET
// Set data by key in the cacheRediBox.hooks.cache.set('cat:fluffy','https://pbs.twimg.com/media/CYY44mYWMAATghb.jpg:small').then(()=>{console.log('Set a fluffy cat in cache');});
DEL
// Delete an item by key in the cacheRediBox.hooks.cache.del('cat').then(data=>{console.log('Deleted item');});
CLEAR
// Delete all items in cacheRediBox.hooks.cache.clear().then(data=>{console.log('Clear all data in cache');});// Delete all matching wildcard items in cacheRediBox.hooks.cache.clear('cat:fluffy:*').then(data=>{console.log('Clear wildcard data from cache');});

Advanced Usage

License

MIT

About

Redis as a cache layer made simple.

Topics

Resources

Stars

5 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages