coa-file-storage
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

coa-file-storage

GitHub license npm version npm downloads PRs Welcome

轻量的文件储存/缓存工具 for Node.js

可为轻量应用、演示应用或简单的静态应用等提供数据存储的能力,使用文件作为存储介质,零依赖,性能高,方便快捷。

特性

  • 简单轻量 不超过 100 行代码,不依赖于其他第三方库
  • 自动缓存 内置内存缓存,不需要频繁读写 IO,性能友好(请在单机应用下使用)
  • TypeScript 全部使用 TypeScript 书写,类型约束、IDE 友好

快速开始

安装

yarn add coa-file-storage

快速开始

import { CoaFileStorage } from 'coa-file-storage'

// 创建一个新的示例
const fileStorage = new CoaFileStorage('/path/file-storage/data')

// 获取一个未设置的值,此时返回undefined
fileStorage.get('key1') // undefined

// 设置储存信息
fileStorage.set('key1', { info: 'this is value' }, 60 * 1000)

// 获取设置的值,能得到正确的存储数据
fileStorage.get('key1') // { info: 'this is value' }

// 超过60秒后,数据过期,返回undefined
fileStorage.get('key1') // undefined

/coa-file-storage/

    Package Sidebar

    Install

    npm i coa-file-storage

    Weekly Downloads

    3

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    4.74 kB

    Total Files

    7

    Last publish

    Collaborators

    • adaex