diskstore

3.1.0 • Public • Published

diskstore

a basic local cache implementation

NPM version Node.js CI Test coverage npm download

Introduction

A basic file cache implementation. It just providers low-level APIs (get, set, delete) to allow you read & atomic write from file cache. You can also create your implementation by inheriting or wrapping it.

Install

npm install diskstore --save

APIs

  • new DiskStore(options)
    • {String} cacheDir - root cache dir
  • async get(relativePath) read data from relativePath if the file exists.
    • {String} relativePath - file path relative to root cache dir
  • async set(relativePath, data) write data to relativePath
    • {String} relativePath - file path relative to root cache dir
    • {Buffer|String} data - the data
  • async delete(relativePath) delete the file
    • {String} relativePath - file path relative to root cache dir

Usage

const diskStore = new DiskStore({
  cacheDir: '/path/cache',
});

await diskStore.set('a/b/c', 'c');
let data = await diskStore.get('a/b/c');
assert.deepEqual(data, Buffer.from('c'));

await diskStore.delete('a/b/c');
data = await diskStore.get('a/b/c');
assert(data === null);

License

MIT

Contributors


leoner


gxcsoccer


fengmk2

This project follows the git-contributor spec, auto updated at Thu Jun 02 2022 15:25:27 GMT+0800.

Readme

Keywords

Package Sidebar

Install

npm i diskstore

Weekly Downloads

8

Version

3.1.0

License

MIT

Unpacked Size

6.18 kB

Total Files

4

Last publish

Collaborators

  • gxcsoccer
  • kangpangpang
  • fengmk2