Class CacheStorage

Cache storage wrapper

  • A simple wrapper around the Storage API with a TTL (Time To Live) per item.
  • Uses JSON.stringify and JSON.parse to serialize and deserialize data.
  • Uses Date.getTime() to calculate the expiration time.

Param

The storage instance (e.g., localStorage or sessionStorage).

Hierarchy

  • CacheStorage

Implements

Constructors

Properties

Methods

Constructors

  • Create a new CacheStorage instance

    Parameters

    • storage: Storage

      storage instance

    Returns CacheStorage

    Throws

    CacheStorageError

Properties

#storage: Storage

Methods

  • Get an item from the storage if not expired

    Type Parameters

    • T = unknown

    Parameters

    • key: string

      key

    Returns null | T

  • Remove an item from the storage

    Parameters

    • key: string

      key

    Returns void

  • Save an item in the storage with a ttl

    Parameters

    • key: string

      key

    • data: unknown

      data to store

    • ttl: number

      time to live in milliseconds

    Returns void

Generated using TypeDoc