1.0.3 • Published 3 years ago

@axtk/memory-storage v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

npm browser node

An in-memory storage with a customizable capacity and with a localStorage-like API

class MemoryStorage

const MemoryStorage = require('@axtk/memory-storage');

const storage = new MemoryStorage(10);

storage.setItem('x', 1);

let x = storage.getItem('x');

new MemoryStorage(capacity?)

Creates an in-memory storage instance with the given capacity.

  • capacity?: number
    • A maximum number of entries to be stored. When the number of entries reaches this value adding a new entry to the storage will cause the first added entry to be removed from the storage to maintain the capacity.
    • Default: Infinity.

The methods of the MemoryStorage class are in line with the Storage interface.