@tadashi/find-in-cache

Find data in cache


Keywords
cache, redis, lib, find
License
MIT
Install
npm install @tadashi/find-in-cache@2.2.1

Documentation

find-in-cache

NPM version Node.js CI Coverage Status

Find data in cache

Install

$ npm i -S @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 - Key prefix
CACHE_REDIS_NAMESPACE string no _lib_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

⚠️ if the ttl is not set, the cache will last forever

Usage

import {find, caching} from '@tadashi/find-in-cache'

await find('foo')
// => undefined

await caching('foo', 'bar', 30)
// => true

await find('foo')
// => bar

License

MIT © Thiago Lagden