The SendCache class provides a static caching mechanism to optimize the process of sending records to remote DWN targets by minimizing redundant sends.

It maintains a cache of record IDs and their associated target DIDs to which they have been sent. This helps in avoiding unnecessary network requests and ensures efficient data synchronization across Decentralized Web Nodes (DWNs).

The cache employs a simple eviction policy to maintain a manageable size, ensuring that the cache does not grow indefinitely and consume excessive memory resources.

Constructors

Properties

Methods

Constructors

Properties

cache: Map<string, Set<string>> = ...

A private static map that serves as the core storage mechanism for the cache. It maps record IDs to a set of target DIDs, indicating which records have been sent to which targets.

sendCacheLimit: number = 100

The maximum number of entries allowed in the cache. Once this limit is exceeded, the oldest entries are evicted to make room for new ones. This limit applies both to the number of records and the number of targets per record.

Methods

  • Checks if a given record ID has been sent to a specified target DID. This method is used to determine whether a send operation is necessary or if it can be skipped to avoid redundancy.

    Parameters

    • id: string

      The unique identifier of the record.

    • target: string

      The DID of the target to check against.

    Returns boolean

    A boolean indicating whether the record has been sent to the target.

  • Adds or updates an entry in the cache for a given record ID and target DID. If the cache exceeds its size limit, the oldest entry is removed. This method ensures that the cache reflects the most recent sends.

    Parameters

    • id: string

      The unique identifier of the record.

    • target: string

      The DID of the target to which the record has been sent.

    Returns void