All Projects → xuexb → Key Cache

xuexb / Key Cache

Licence: mit
Storing data in the form of key into the file

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Key Cache

Java Knowledge Mind Map
【🌱🌱Java服务端知识技能图谱】用思维脑图梳理汇总Java服务端知识技能
Stars: ✭ 787 (+9737.5%)
Mutual labels:  cache
Simple Cache
An easy to use Caching trait for Laravel's Eloquent Models.
Stars: ✭ 19 (+137.5%)
Mutual labels:  cache
Hazelcast Hibernate
A distributed second-level cache for Hibernate
Stars: ✭ 24 (+200%)
Mutual labels:  cache
Cleanmywechat
自动删除 PC 端微信缓存数据,包括从所有聊天中自动下载的大量文件、视频、图片等数据内容,解放你的空间。
Stars: ✭ 816 (+10100%)
Mutual labels:  cache
Go Reflectx
Go reflection library to find struct field by its tag
Stars: ✭ 19 (+137.5%)
Mutual labels:  cache
Deepcache
Cache design for CNN on mobile
Stars: ✭ 22 (+175%)
Mutual labels:  cache
Smartsql
SmartSql = MyBatis in C# + .NET Core+ Cache(Memory | Redis) + R/W Splitting + PropertyChangedTrack +Dynamic Repository + InvokeSync + Diagnostics
Stars: ✭ 775 (+9587.5%)
Mutual labels:  cache
Go Cache Demo
Demo repository on how to use server side cache in Go
Stars: ✭ 26 (+225%)
Mutual labels:  cache
Lazycache
An easy to use thread safe in-memory caching service with a simple developer friendly API for c#
Stars: ✭ 901 (+11162.5%)
Mutual labels:  cache
Cache Service Provider
A Cache Service Provider for Silex, using the doctrine/cache package
Stars: ✭ 23 (+187.5%)
Mutual labels:  cache
Jsonlite
A simple, self-contained, serverless, zero-configuration, json document store.
Stars: ✭ 819 (+10137.5%)
Mutual labels:  json-data
React Native Cached Image
CachedImage component for react-native
Stars: ✭ 890 (+11025%)
Mutual labels:  cache
Vue Navigation
A page navigation library, record routes and cache pages, like native app navigation. 一个页面导航库,记录路由并缓存页面,像原生APP导航一样。
Stars: ✭ 920 (+11400%)
Mutual labels:  cache
Django Cachalot
No effort, no worry, maximum performance.
Stars: ✭ 790 (+9775%)
Mutual labels:  cache
Cache Chunk Store
In-memory LRU (least-recently-used) cache for abstract-chunk-store compliant stores
Stars: ✭ 24 (+200%)
Mutual labels:  cache
Yac
A fast, lock-free, shared memory user data cache for PHP
Stars: ✭ 782 (+9675%)
Mutual labels:  cache
Httpcache
Get a working HTTP Cache in Go (Golang) with only 3 lines of code!!!!
Stars: ✭ 17 (+112.5%)
Mutual labels:  cache
Wordpress Rest Cache
WordPress Plugin to lazy cache HTTP requests in database and update via cron.
Stars: ✭ 8 (+0%)
Mutual labels:  cache
Fire Emblem Working Title
A fledgling project wrangling Fire Emblem: Heroes stats
Stars: ✭ 25 (+212.5%)
Mutual labels:  json-data
Ufodiff
UFO source file diff application
Stars: ✭ 23 (+187.5%)
Mutual labels:  json-data

key-cache

中文文档

Storing data in the form of key into the file


code style fecs NPM Version NPM Downloads Linux Build Windows Build Test Coverage Dependencies

Install

requires node 4+

npm install key-cache --save

Use

// Create reference
var KeyCache = require('key-cache');

// Examples of objects
var cache = new KeyCache(options);

// Here you can use to manipulate the cache api
cache.get('balbalbal');

The default configuration

options.dir

Cache directory path based on the current run directory

/**
 * @default key-cache installation path of .cache/ directory
 * @type {String}
 */

options.timeout

Save time, in seconds, if empty will always exist

/**
 * @default null
 * @type {number|null}
 */

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 {Boolean}
 */

Api

set

Write data to a file

/**
 * @param {string} key
 * @param {Object|string} value
 * @param {Object|undefined} options        If there will override the default configuration
 * @return {Object} this
 */
set(key, value, options = {})

get

Get data from files

/**
 * @param  {string} key
 *
 * @return {Object|string|null}             If there is no time has expired or will return null
 */
get(key)

remove

Delete data, and delete files

/**
 * @param  {string|undefined} key
 *
 * @return {Object}     this
 */
remove(key)

Examples

Simple

var cache = new KeyCache();

cache.set('name', 'key-cache');

console.log(cache.get('name'));

cache.remove('name');

console.log(cache.get('name')); // => null

Custom cache directory

var cache = new KeyCache({
    dir: '../cache/'
});

cache.set('name', 'key-cache');

// override the default configuration
cache.set('name2', 'key-cache', {
    dir: './cache2'
});

Set the expiration time

var cache = new KeyCache({
    timeout: 3
});

cache.set('name', 'key-cache');

// override the default configuration
cache.set('age', 1, {
    timeout: 5
});

setTimeout(function(){
    console.log(cache.get('name')); // => null
    console.log(cache.get('age')); // => 1
}, 3000);

Delete Cache

var cache = new KeyCache();

cache.set('name', 'key-cache');
cache.set('age', 1);

// Delete single
cache.remove('name');

console.log(cache.get('name')); // => null
console.log(cache.get('age')); // => 1

// Delete all
cache.remove();

console.log(cache.get('age')); // => null

md5key

Do not use md5 named cache file

var cache = new KeyCache({
    md5key: false
});

cache.set('key', 'key-cache'); // => filename is key.json
cache.set('age', 1); // => filename is age.json
cache.set('this a space +-', 1); // => filename is thisaspace-.json
cache.set('中文', 1); // => filename is 中文.json

Develop

Use es6 development, compiler-dependent babel 6.x

// Run the compiler, the es6 code from the compiled into lib in src
npm run compile

// Monitor file changes and runs the compiler
npm run watch

// Use fecs run Style Checker
npm run check

// Use mocha run the test case
npm run test

// Run the test cases and code coverage
npm 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

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].