npm install siwi-cache
yarn add siwi-cache
参数 | 类型 | 是否必选 | 含义 |
---|---|---|---|
key | String | 是 | 缓存key |
value | String | Number | 是 | 值 |
expire | Number | 否 | 缓存时长 -1 为永久缓存 默认值-1 |
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
参数 | 类型 | 是否必选 | 含义 |
---|---|---|---|
key | String | 是 | 缓存key |
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
参数 | 类型 | 是否必选 | 含义 |
---|---|---|---|
key | String | 是 | 缓存key |
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
参数 | 类型 | 是否必选 | 含义 |
---|---|---|---|
key | String | 是 | 缓存key |
value | Number | 是 | 增长值 可为负数 |
expire | Number | 否 | 缓存时长 -1 为永久缓存 默认值-1 |
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
${process.env.PWD}/cache