# storage-cachelib-js

> Cache library with ttl and reflection to persistent storages

Latest version **1.0.1** (published 2023-06-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install storage-cachelib-js
pnpm add storage-cachelib-js
yarn add storage-cachelib-js
bun add storage-cachelib-js
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-06-11 |
| First published | 2023-06-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | thewillwillhelp |
| Maintainers | thewillwillhelp |
| Keywords | cache, js |

## Links

- npm: https://www.npmjs.com/package/storage-cachelib-js
- Repository: https://github.com/thewillwillhelp/storage-cachelib
- Homepage: https://github.com/thewillwillhelp/storage-cachelib#readme
- Issues: https://github.com/thewillwillhelp/storage-cachelib/issues
- npm.io page: https://npm.io/package/storage-cachelib-js

## Dependencies (1)

- [cachelib-js](https://npm.io/package/cachelib-js.md) ^1.0.2

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.1 (latest) — 2023-06-11
- 1.0.0 — 2023-06-11

## README

JS Cache library that allows to store data and setup TTL.
Also reflect cached data to some persinstent storage like localStorage and sessionStorage.
Based on cachelib-js.

Usage:

    const { StorageCacheService } = require('storage-cachelib-js');

    const cacheService = new CacheService({
        id: 'test'
    });

    // add external storage config
    cacheService.addExternalStorage({
        id: 'storage1',
        type: 'localStorage', // also available 'sessionStorage' and 'custom'
        // storage: {} - to provide custom storage with Web Storage interface
        interval: 10000, // will save data from cache to external storage in this interval
        intervalInOperations: 10, // will save data from cache to external storage
        // each 10th get/set/remove operation
    });

    // restore data from external storage
    cacheService.restoreData({ id: 'storage1' });
    // should be called after external storages are configured
    // if no id provoided, then first added external storage will be used

    // subscribe to service events (SET, GET, REMOVE)
    cacheService.addListener(CacheService.events.SET, (event) => { /* response on SET event */ });

    // set value to cache which will be non-actual after 10 sec
    cacheService.set('key', { value: 'any value' }, { ttl: 10000 });

    // get value
    const result = cacheService.get('key');

    // remove value
    cacheService.remove('key');

    // extract full data
    const fullCacheData = cacheService.extract();

    // preload data to service
    cacheService.load(fullCacheData);

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