key-cache
Storing data in the form of key into the file
Install
requires node 4+
npm install key-cache --save
Use
// Create referencevar KeyCache = ; // Examples of objectsvar cache = options; // Here you can use to manipulate the cache apicache;
The default configuration
options.dir
Cache directory path based on the current run directory
/** * @default key-cache installation path of .cache/ directory * @type */
options.timeout
Save time, in seconds, if empty will always exist
/** * @default null * @type */
options.md5key
Set whether to use md5 named cache file name,To path is valid, it will filter the illegal character key, in addition to Chinese, letters, numbers, -, other characters will be ignored outside _, regular use is/[^\u4e00-\u9fa5a-zA-Z\_\-0-9]/g
.
/** * @default true * @type */
Api
set
Write data to a file
/** * @param * @param * @param * @return */
get
Get data from files
/** * @param * * @return */
remove
Delete data, and delete files
/** * @param * * @return */
Examples
Simple
var cache = ; cache; console; cache; console; // => null
Custom cache directory
var cache = dir: '../cache/'; cache; // override the default configurationcache;
Set the expiration time
var cache = timeout: 3; cache; // override the default configurationcache; ;
Delete Cache
var cache = ; cache;cache; // Delete singlecache; console; // => nullconsole; // => 1 // Delete allcache; console; // => null
md5key
Do not use md5 named cache file
var cache = md5key: false; cache; // => filename is key.jsoncache; // => filename is age.jsoncache; // => filename is thisaspace-.jsoncache; // => filename is 中文.json
Develop
Use es6 development, compiler-dependent babel 6.x
// Run the compiler, the es6 code from the compiled into lib in srcnpm run compile // Monitor file changes and runs the compilernpm run watch // Use fecs run Style Checkernpm run check // Use mocha run the test casenpm run test // Run the test cases and code coveragenpm run test-cov
Changelog
1.0.0
Add nodejs V8 test environment
0.3.1
add .getAll()
0.3.0
stand by node 4.x+
0.2.9
Modify api: fs.existsSync
=>fs.statSync
0.2.8
Add nodejs 6.x test environment
0.2.7
Update test case to ES6
0.2.6
babel 6.x upgrade to compile
0.2.3
- Modify
precommit
toprepush
- Add release.sh, refer vue
0.2.1
Return Value Type Repair function
when the value is, the change from the undefined
to null
~
0.2.0
Add options.md5key
parameter is used to set whether to use md5 named cache file name
0.1.x
Optimized code, add a test case
License
MIT