An open API service indexing awesome lists of open source software.

https://github.com/budarin/cache-store

Service for storing json data in the browser cache
https://github.com/budarin/cache-store

Last synced: 15 days ago
JSON representation

Service for storing json data in the browser cache

Awesome Lists containing this project

README

        

# cache-store

Service for storing json data in the browser cache.

The service is a simple alternative to IndexedDB, but without an overhead for the description of the structure and the ceremonies for updating and changing structure.

This storage is convenient both for direct storage of unstructured data in the form of JSON and as a common data storage shared by the client and the service worker.

## Instalation

```bash
yarn add @budarin/cache-store
```

## Usage

```ts
import { CacheStore } from '@budarin/cache-store';

const store = new CacheStore('kv-storage'); //ew CacheStore('kv-storage', console);
const usersStore = [
{
name: 'Ivan',
age: 20,
},
{
name: 'Petr',
age: 21,
},
];

await store.setItem('users', usersStore);

const users = await store.getItem('users');
users.forEach((user) => console.log(user));

await store.removeItem('users');
await store.clear('kv-storage');
```