axtk / memory-storage

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

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


Languages

Language:JavaScript 100.0%