carbon-cache
v0.0.9
Published
A simple and light weight extendable cache
Downloads
5
Maintainers
Readme
carbon-cache
carbon-cache
Is a simple, light weight and extendable in memory cache.
Install
$ npm install --save carbon-cache
Example
// Using good old require
const { CarbonCache } = require('carbon-cache');
// Using import
import { CarbonCache } from 'carbon-cache';
const myCache = new CarbonCache(100); // Create myCache valid for 100 seconds i.e. TTL is 100 seconds.
const myCache = new CarbonCache(); // TTL is completly optional. This is perfectly valid.
// Populate Cache with JSON data
myCache.importJson(_JSON data_);
// Put an item into the Cache
myCache.put(_key_, _value_, _replaceIfKeyAlreadyExist?: Boolean_);
// Check if a key exist in Cache
myCache.has(_key_);
// Get an item from the Cache
myCache.get(_key_);
// Delete an item from the Cache
myCache.del(_key_);
// Export complete contents of Cache as JSON
myCache.exportJson();
// Flush complete contents of Cache
myCache.flush();
// Check if the cache is empty
myCache.isEmpty();
The TTL is for complete Cache and validity of the complete cache is extended by the TTL provided while creating the Cache when a new item is added to the Cache. If no TTL specified while creating Cache, it lives on as long as the node process is alive.