Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including elegant-storage with all npm packages installed. Try it out:

var elegantStorage = require("elegant-storage")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

elegant-storage v1.0.9

Supports the use of indexeddb to store data, support setting expiration time, manual failure, cache data grouping

优雅的基于indexedDB前端缓存工具

🌰 主要解决的问题是:

  1. 较大数据量缓存
  2. 支持缓存失效设置
  3. 缓存分组与批量设置失效

命令介绍

🍎 下载

npm i --save elegant-storage

🍏 初始化

import ElegantStorage from 'elegant-storage'

const storage = new ElegantStorage()

🍑 设置缓存
set(key, value, options)

  • key 缓存键
  • value 缓存内容
  • options 缓存相关设置
storage.set('people', {name: 'walker'}, {
  expires: 6000, // 单位秒
  group: 'card'  // 缓存分组
}).then(res => console.log('设置完成'))

🍐 获取缓存
get(key)

storage.get('people')
  .then(res => console.log('people is:', res))

🍌 删除缓存
remove(key)

storage.remove('people')
  .then(res => console.log('删除成功'))

🎃 以分组批量删除缓存
removeGroup(groupName)

storage.removeGroup('card')
  .then(() => console.log('已删除card分组'))

🍓 删除所有
removeAll()

storage.removeAll()
  .then(() => console.log('已删除全部'))

🍇 获取缓存长度
length()

storage.length()
  .then(res => console.log(res))

🍉 获取缓存keys
keys()

storage.keys()
  .then(keys => console.log(keys))

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free