siwi-cache
nodejs 文件缓存 提供set get del incr 等方法
install
use npm
npm install siwi-cache
use yarn
yarn add siwi-cache
Example
set
参数 | 类型 | 是否必选 | 含义 |
---|---|---|---|
key | String | 是 | 缓存key |
value | String | Number | 是 | 值 |
expire | Number | 否 | 缓存时长 -1 为永久缓存 默认值-1 |
const Cache = const options = cache_path: `/cache`const cache = { this } async { const res = await cache console } moduleexports =
console true
get
参数 | 类型 | 是否必选 | 含义 |
---|---|---|---|
key | String | 是 | 缓存key |
const Cache = const options = cache_path: `/cache`const cache = { this } async { const res = await cache console } moduleexports =
console this is a test
del
参数 | 类型 | 是否必选 | 含义 |
---|---|---|---|
key | String | 是 | 缓存key |
const Cache = const options = cache_path: `/cache`const cache = { this } async { const res = await cache console } moduleexports =
console true
incr
参数 | 类型 | 是否必选 | 含义 |
---|---|---|---|
key | String | 是 | 缓存key |
value | Number | 是 | 增长值 可为负数 |
expire | Number | 否 | 缓存时长 -1 为永久缓存 默认值-1 |
const Cache = const options = cache_path: `/cache`const cache = { this } async { const res = await cache console } moduleexports =
console 100
缓存文件存储路径 与名称
你可以实例化siwi-cache 的时候 通过传入 options['cache_path'] 自定义缓存文件存储地址 默认存储路径是:
${process.env.PWD}/cache