find-in-cache
Find data in cache
Install
$ npm i @tadashi/find-in-cache
Environment variable
variable | type | required | default | description |
---|---|---|---|---|
REDIS | string | no | 127.0.0.1:6379 | Addresses to connect |
REDIS_PWD | string | no | - | Redis password |
CACHE_REDIS_PREFIX | string | no | lib | Key prefix |
CACHE_REDIS_NAMESPACE | string | no | find-in-cache | Avoid conflicts between caches |
CACHE_REDIS_DB | number | no | 0 | Number of database |
CLEAR_CACHE_FIRST_RUN | boolean | no | true | Clear cache when app is started |
See more about REDIS
and REDIS_PWD
in:
https://github.com/lagden/connect-redis
API
find(key: any): any
parameter | type | required | default | description |
---|---|---|---|---|
key | any | yes | - | data key name |
caching(key: any, value: any, ttl: number): boolean
parameter | type | required | default | description |
---|---|---|---|---|
key | any | yes | - | data key name |
value | any | yes | - | data |
ttl | number | no | - | cache lifetime in seconds |
ttl
is not set, the cache will last forever
Usage
import {find, caching, cache} from '@tadashi/find-in-cache'
await find('foo')
// => undefined
await caching('foo', 'bar', 30)
// => true
await find('foo')
// => bar
await cache.clear()
// => cache was cleared
Donate ❤️
BTC: bc1q7famhuj5f25n6qvlm3sssnymk2qpxrfwpyq7g4
License
MIT © Thiago Lagden