@micheldever/storage v1.0.4
Installation
This package is distributed via npm. You can install it as a dependency in your project by running:
yarn add @micheldever/storageUsage
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.