Code Monkey home page Code Monkey logo

plugin-storage's Introduction

介绍

CircleCI NPM Version NPM Downloads npm bundle size Coverage Status

Feature

  1. 过期控制
  2. 版本隔离

安装

$ npm i @beautywe/plugin-storage
import { BtApp } from '@beautywe/core';
import storage from '@beautywe/plugin-storage';

const app = new BtApp();
app.use(storage({
    // options
}))

使用

app.storage.set(key, value, options);
app.storage.get(key, options);
app.storage.remove(key);
app.storage.clear();

storage(options)

options.expire

设置缓存时间,默认是 7 ,单位是「天」

options.appVersion

设置当前应用的版本号,后续的所有缓存,都会关联到当前版本号中,并且会有版本隔离:

app.use({ appVersion: '0.0.1' });
app.set('name', 'jc');

// 返回 jc
app.get('name');

// 当版本更新后
app.use({ appVersion: '0.0.2' });

// 返回 undefined;
app.get('name');

set(key, value, options)

key

要设置的缓存名

value

要设置的缓存

options.expire

缓存的过期时间,默认跟 stoarge(options) 设置的一致。

options.appVersion

缓存的对应应用版本,默认跟 storage(options) 设置的一致。

get(key, options)

key

获取的缓存名

options.appVersion

缓存的对应应用版本,默认跟 storage(options) 设置的一致。

options.ignoreVersion

是否忽略版本检查,默认为 false,设置为 true 时,则返回的缓存不做版本检查

options.ignoreExpire

是否忽略过期时间检查,默认为 false,设置为 true 时,则返回的缓存不做过期时间检查

remove(key)

清除特定的缓存

clear()

清除所有缓存

plugin-storage's People

Contributors

jerryc8080 avatar

Stargazers

 avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

giegie1970

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.