ds-cache
Provide a tool that is simple data storage as cache and easy to use.
The feature includes:
- File size as Cache size.
- Implement the LRU algorithm.
Documents
Generate the document.
$ codo lib/cache.coffee
Or you can go to CoffeeDoc.info watch this doc.
Installation
$ npm i ds-cache
API
-
Cache(option) - Constructor.
- option.limit_bytes: limit the cache file size. Default: '100K'
- option.auto_save: enable auto save cache. Default: false
- option.filename: full name of save file. Default: 'ds_cache.json'
-
set(key, value) - Put data into cache.
- key: the key of data.
- val: the value of data.
-
get(key) - Catch data via key.
- key: the key that you want to catch the data.
-
clear([key]) - Remove the data via key. Clear all data in the cache if you invoke this method without any arguments
- key: optional. You could remove the data by key, either remove all data without any arguments.
-
save() - Write the cache into the file.
-
load() - Load the cache from file.
-
size() - Return the number of data in the cache.
-
content() - Return the JSON string of cache.
Examples
var Cache = ; // initial the cache instancevar cache = limit_bytes: '2M' // limit file size auto_save: true filename: 'ds_cache.json' ; // add a datacache; // get value via keycache; // clear data via keycacheclear'name'; // clear all datacacheclear;
License
The MIT License (MIT)