# siwi-cache
**Repository Path**: siwi/siwi-cache
## Basic Information
- **Project Name**: siwi-cache
- **Description**: siwi-cache nodejs 文件缓存
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2018-03-27
- **Last Updated**: 2020-12-20
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
[](https://www.npmjs.com/package/siwi-cache)
[](https://www.npmjs.com/package/siwi-cache)
# siwi-cache
# 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 |
```js
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
| 参数 |
类型 |
是否必选 |
含义 |
| key |
String |
是 |
缓存key |
```js
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
| 参数 |
类型 |
是否必选 |
含义 |
| key |
String |
是 |
缓存key |
```js
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
| 参数 |
类型 |
是否必选 |
含义 |
| key |
String |
是 |
缓存key |
| value |
Number |
是 |
增长值 可为负数 |
| expire |
Number |
否 |
缓存时长 -1 为永久缓存 默认值-1 |
```js
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