Standard storage provider for storing web data
npm install @micheldever/storagegit clone https://mtsweb@dev.azure.com/mtsweb/oss/_git/storage
This package is distributed via npm. You can install it as a dependency in your project by running:
``bash`
yarn add @micheldever/storage
Create a new StorageEntity instance and use it to interact with your storage entries:
`typescript
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.
`typescript`
entity.addAdapter(new MemoryStorageAdapter());
`typescript`
await entity.set('testKey', createStorageEntry('testValue', 10000));
Entries stored within a StorageEntity can define their own ttl in milliseconds. After this timeundefined
has elapsed, the next time the value is accessed you will get instead. Entries withttl
a of Infinity will never expire and will be available indefinitely.
`typescript`
const value = await entity.get('testKey');
`typescript`
await entity.del('testKey');
This package comes preconfigured with two adapters. Additional adapters can be created by
implementing the StorageAdapter` interface.