1.1.1 • Published 6 years ago

lc-cache v1.1.1

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

LocalCache

LocalCache 是一个处理缓存数据的工具库,包含对象缓存,cookie存储,localStorage和seesionStorage存储

Example

GitHub地址:https://github.com/Future-component/LocalCache

demo地址:https://github.com/Future-component/LocalCache/blob/master/example/index.html

实例化对象

new localCache({ debug: true, prefix: 'prefix' });

参数类型含义默认值
debugboolean是否开启debug模式false
prefixstringkey的前缀'lc'

实例的API

参数类型含义默认值
createCachefunction创建cache对象无
cookieobject基于cookie的存储
storagefunction基于storage的存储localStorage

createCache样例

var cache = new localCache({ debug: true });

var typeCache = cache.createCache();
typeCache('name');
typeCache('name', 'beth');

cookie样例

var cache = new localCache({ debug: true });

// 获取所有的cookie对象
var cookies = cache.cookie.getAll();

// 设置cookie
cache.cookie.set('xq', JSON.stringify({ name: 'beth' }), 1);

// 获取cookie
var xq = cache.cookie.get('xq');
console.log(xq && JSON.parse(xq))

// 删除cookie
cache.cookie.remove('xq');

// 设置cookie
cache.cookie.set('xq', JSON.stringify({ name: 'beth' }), 1);

// 清除所有cookie
cache.cookie.clear();

storage样例

var cache = new localCache({ debug: true });

// 初始化storage对象
var cacheStorage = cache.storage();

// 设置storage
cacheStorage.set('xq', JSON.stringify({ name: 'beth' }))

// 获取所有storage对象
var storages = cacheStorage.getAll();

// 获取storage
var xq = cacheStorage.get('xq');
console.log(xq && JSON.parse(xq))

// 移除storage
cacheStorage.remove('xq');

// 设置storage
cacheStorage.set('xq', JSON.stringify({ name: 'beth' }))

// 清空所有storage
cacheStorage.clear();
1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago