@micheldever/storage

1.0.2 • Public • Published


@micheldever/storage

Standard storage provider for storing web data


git clone https://mtsweb@dev.azure.com/mtsweb/oss/_git/storage

Installation

This package is distributed via npm. You can install it as a dependency in your project by running:

yarn add @micheldever/storage

Usage

Create a new StorageEntity instance and use it to interact with your storage entries:

import { StorageEntity, createStorageEntry } from '@micheldever/storage';
import { MemoryStorageAdapter } from '@micheldever/storage/adapters';

const entity = new StorageEntity(new MemoryStorageAdapter());

You can attach one or more storage adapters to your storage instance during initialization. Alternatively, you can attach additional adapters at any time using the addAdapter method.

entity.addAdapter(new MemoryStorageAdapter());

Set a value

await entity.set('testKey', createStorageEntry('testValue', 10000));

Entries stored within a StorageEntity can define their own ttl in milliseconds. After this time has elapsed, the next time the value is accessed you will get undefined instead. Entries with a ttl of Infinity will never expire and will be available indefinitely.

Retrieve a value

const value = await entity.get('testKey');

Delete a value

await entity.del('testKey');

Adapters

This package comes preconfigured with two adapters. Additional adapters can be created by implementing the StorageAdapter interface.

Readme

Keywords

none

Package Sidebar

Install

npm i @micheldever/storage

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

17.1 kB

Total Files

11

Last publish

Collaborators

  • hwll