1.0.4 • Published 10 months ago

@micheldever/storage v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

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.

1.0.4

10 months ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago