siwi-cache
v1.0.7
Published
siwi-cache nodejs 文件缓存
Downloads
27
Maintainers
Readme
siwi-cache
nodejs 文件缓存 提供set get del incr 等方法
install
use npm
npm install siwi-cache
use yarn
yarn add siwi-cache
Example
set
const Cache = require('siwi-cache')
const options = {
cache_path: `${process.env.PWD}/cache`
}
const cache = new Cache()
class Example {
constructor() {
this.init()
}
async init () {
const res = await cache.set('test', 'this is a test', 60)
console.log(res)
}
}
module.exports = new Example()
console true
get
const Cache = require('siwi-cache')
const options = {
cache_path: `${process.env.PWD}/cache`
}
const cache = new Cache()
class Example {
constructor() {
this.init()
}
async init () {
const res = await cache.get('test')
console.log(res)
}
}
module.exports = new Example()
console this is a test
del
const Cache = require('siwi-cache')
const options = {
cache_path: `${process.env.PWD}/cache`
}
const cache = new Cache()
class Example {
constructor() {
this.init()
}
async init () {
const res = await cache.del('test')
console.log(res)
}
}
module.exports = new Example()
console true
incr
const Cache = require('siwi-cache')
const options = {
cache_path: `${process.env.PWD}/cache`
}
const cache = new Cache()
class Example {
constructor() {
this.init()
}
async init () {
const res = await cache.incr('incr', 100)
console.log(res)
}
}
module.exports = new Example()
console 100
缓存文件存储路径 与名称
你可以实例化siwi-cache 的时候 通过传入 options['cache_path'] 自定义缓存文件存储地址 默认存储路径是:
${process.env.PWD}/cache