Socket
Book a DemoInstallSign in
Socket

@axtk/volatile-storage

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@axtk/volatile-storage

A storage with a customizable item lifetime and capacity with a localStorage-like API

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

npm browser node

A storage with a customizable item lifetime and capacity with a localStorage-like API

class VolatileStorage

const VolatileStorage = require('@axtk/volatile-storage');

const storage = new VolatileStorage({
    storage: window.localStorage,
    maxAge: 60000, // in milliseconds
    capacity: 100
});

await storage.setItem('x', 1);
await storage.setItem('status', 'done', {maxAge: 120000});

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

new VolatileStorage(props?)

  • props?: object
  • props.storage?: Storage | async<Storage>
    • An external storage instance with a localStorage-like API (like window.localStorage itself, window.sessionStorage, or localForage) where all values will actually be stored.
    • Default: in-memory storage.
  • props.maxAge?: number
    • A storage entry lifetime in milliseconds. (A stored value may linger on the storage after its lifetime elapses until the next interaction with the storage reveals the value has expired and removes it.)
    • Default: Infinity.
  • props.capacity?: number
    • A maximum number of entries on the storage. When the number of entries reaches the capacity value and a new item is added to the storage, the first added item is removed from the storage to maintain the capacity.
    • Default: Infinity.
  • props.ns?: string
    • A storage entry key namespace. It can be useful to isolate multiple instances of VolatileStorage sharing the same external storage (like window.localStorage).
    • Default: ''.
  • props.version?: string | number
    • A version, or a revision identifier, of the storage. Changing this value will expire values stored in an external storage (like window.localStorage) under a different version.
    • Default: undefined.

The methods of the VolatileStorage class are asynchronous versions of the Storage methods.

Keywords

storage

FAQs

Package last updated on 23 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts