https://github.com/node-modules/diskstore
a local cache implement
https://github.com/node-modules/diskstore
Last synced: 11 days ago
JSON representation
a local cache implement
- Host: GitHub
- URL: https://github.com/node-modules/diskstore
- Owner: node-modules
- License: mit
- Created: 2017-10-11T09:04:22.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-17T15:46:55.000Z (over 2 years ago)
- Last Synced: 2025-06-04T16:46:27.736Z (21 days ago)
- Language: JavaScript
- Size: 19.5 KB
- Stars: 6
- Watchers: 12
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# diskstore
a basic local cache implementation
[![NPM version][npm-image]][npm-url]
[](https://github.com/node-modules/diskstore/actions/workflows/nodejs.yml)
[![Test coverage][codecov-image]][codecov-url]
[![npm download][download-image]][download-url][npm-image]: https://img.shields.io/npm/v/diskstore.svg?style=flat-square
[npm-url]: https://npmjs.org/package/diskstore
[codecov-image]: https://codecov.io/gh/node-modules/diskstore/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/node-modules/diskstore
[download-image]: https://img.shields.io/npm/dm/diskstore.svg?style=flat-square
[download-url]: https://npmjs.org/package/diskstore## 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
```bash
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
```js
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](LICENSE)
## Contributors
|[
leoner](https://github.com/leoner)
|[
gxcsoccer](https://github.com/gxcsoccer)
|[
fengmk2](https://github.com/fengmk2)
|
| :---: | :---: | :---: |This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Thu Jun 02 2022 15:25:27 GMT+0800`.