# cloudbase-accesstoken-cache

> cloudbase-accesstoken-cache , use cloudbase database to manager your accesstoken easily !

Latest version **1.1.2** (published 2021-11-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install cloudbase-accesstoken-cache
pnpm add cloudbase-accesstoken-cache
yarn add cloudbase-accesstoken-cache
bun add cloudbase-accesstoken-cache
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2021-11-19 |
| First published | 2021-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | SonOfMagic |
| Maintainers | icebreaker |
| Keywords | cloudbase, 微信, 公众号, 小程序, accesstoken, 缓存, 过期 |

## Links

- npm: https://www.npmjs.com/package/cloudbase-accesstoken-cache
- Repository: https://github.com/sonofmagic/cloudbase-accesstoken-cache
- Homepage: https://github.com/sonofmagic/cloudbase-accesstoken-cache#readme
- Issues: https://github.com/sonofmagic/cloudbase-accesstoken-cache/issues
- npm.io page: https://npm.io/package/cloudbase-accesstoken-cache

## Recent versions

- 1.1.2 (latest) — 2021-11-19
- 1.1.1 — 2021-11-18
- 1.1.0 — 2021-11-18
- 1.0.2 — 2021-11-17
- 1.0.1 — 2021-11-17
- 1.0.0 — 2021-11-17

## README

# cloudbase-accesstoken-cache

> 微信公众号和小程序的 Access Token 小助手， 轻松快捷的管理您的Token策略

## Usage

### ESM / Typescript

```ts
import { init } from '@cloudbase/node-sdk'
import { SingleCacheManager } from 'cloudbase-accesstoken-cache'

const app = init({
  secretId,
  secretKey,
  env
})

const db = app.database()
const manager = new SingleCacheManager({
  appid,
  db,
  secret
})
// 获取 token (有缓存机制)
const token = await manager.getAccessToken()
```

### CJS (commonjs)

```js
const tcb = require('@cloudbase/node-sdk')
const { SingleCacheManager } = require('cloudbase-accesstoken-cache')

const app = tcb.init({
  secretId,
  secretKey,
  env
})

const db = app.database()
const manager = new SingleCacheManager({
  appid,
  db,
  secret
})
// 获取 token (有缓存机制)
const token = await manager.getAccessToken()
```

## Class

### SingleCacheManager

`options` 可以通过 `.d.ts` 定义感知出来

有 `2` 种策略，通过构造方法的 `memoize` 配置项开启 ,`default: true`

开启后会在内存中同步缓存，相当于一套 2 级缓存机制,顺序为:

1. 内存缓存
2. Cloudbase DB 数据库缓存
3. 重新获取

不开启的策略为:

1. Cloudbase DB 数据库缓存
2. 重新获取

如果你有更复杂的需求，请提 [`issue`](https://github.com/sonofmagic/cloudbase-accesstoken-cache/issues)

---
_Source: https://npm.io/package/cloudbase-accesstoken-cache · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
