New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@cave/cache

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cave/cache - npm Package Compare versions

Comparing version
1.0.0
to
1.0.1
+4
-8
package.json
{
"name": "@cave/cache",
"version": "1.0.0",
"version": "1.0.1",
"publishConfig": {

@@ -23,5 +23,2 @@ "access": "public"

"devDependencies": {
"@types/async-retry": "^1.4.5",
"@types/fs-extra": "^9.0.13",
"@types/glob": "^8.0.0",
"@types/jest": "^27.0.2",

@@ -45,3 +42,3 @@ "@types/node": "^16.11.6",

"type": "git",
"url": "git+https://github.com/seala/cache.ts.git"
"url": "git+https://github.com/cave-packages/cache.git"
},

@@ -52,9 +49,8 @@ "keywords": [],

"bugs": {
"url": "https://github.com/seala/cache.ts/issues"
"url": "https://github.com/cave-packages/cache/issues"
},
"homepage": "https://github.com/seala/cache.ts#readme",
"homepage": "https://github.com/cave-packages/cache#readme",
"dependencies": {
"fs-extra": "^10.1.0",
"level": "^8.0.0"
}
}
# @cave/cache
基于 leveldb 的缓存方案
## 安装
```typescript
npm i '@cave/cache'
```
## demo
```typescript
import { resolve } from 'path';
import { CCache } from '../src/main';
const cache = new CCache(resolve(__dirname, '../db'));
async function demo() {
// 初始化,主要执行level open操作
await cache.init();
// 设置缓存
const key = 'unique_id';
const value = { foo: 1 };
await cache.set(key, value);
// 读取缓存
const data = await cache.get<{ foo: number }>(key);
console.log(data);
console.log(data.foo);
// 清除7天之前缓存的数据
await cache.clean(7 * 24 * 3600000);
}
demo();
```
## API
### 属性
#### cache.db
指向 `Level`实例
### 方法
#### await cache.init()
主要执行 levedb 的 open 操作
#### await cache.set(key: string, value: unknown)
设置缓存数据
#### await cache.get<T>(key: string)
读取缓存数据,`<T>`可以定义返回数据的类型
#### await cache.clean(past_time: number = 7 \* 24 \* 3600000)
删除`past_time`毫秒之前缓存的数据,默认是删除 7 天前缓存的数据