@graphshieldhq/cache
v0.0.4
Published
An opinionated cache management module
Downloads
8
Maintainers
Readme
Cache Module
An opinionated cache management module that works bith in-memory and with Redis.
💡 Features
🚀 Get Started
Installation
npm install --save @graphshieldhq/cache
Initialization
import cache from '@graphshieldhq/cache'
cache.init({
cache_driver = 'in-memory',
redis_host = 'localhost',
redis_port = 6379,
redis_database_index = 0,
redis_tls = false,
redis_password = '',
redis_reconnect_attempts = 0,
redis_reconnect_delay = 1000,
cache_keys_prefix = 'cache:',
logging = console.log
})
The initialization options must be an object with properties as specified in the options schema.
Usage
// Set data
const setResult = await cache.set({
key: 'test',
value: 'test',
ttl: 1000 // In milliseconds
})
console.log(setResult) // Is `true` if successful
// Get data
const value = await cache.get({ key: 'test' })
console.log(value)