Function withCacheJitter

  • Creates a plugin that adds random jitter to TTL values on cache add and put operations.

    Applying jitter to TTLs helps prevent cache stampedes / thundering-herd problems by staggering the expiration times of cache entries that were originally created with the same TTL.

    Parameters

    • settings: WithCacheJitterSettings = {}

      Configuration for the jitter behaviour.

      • OptionaldefaultJitter?: number

        The jitter factor as a ratio of the original TTL. For example, 0.2 means the TTL will be randomly adjusted by 20 %. A value of 0 disables jitter entirely.

        0.2
        

    Returns PluginFn<ICacheAdapter>

    A middleware plugin that wraps an ICacheAdapter.

    IMPORT_PATH: "@daiso-tech/core/cache/plugins"

    0.2