Documentation
    Preparing search index...

    Class LRUCache<V>

    In-memory cache that keeps at most max entries, evicting the least recently used one first. Entries can expire after a ttl.

    Array keys are joined with a space, so ['a', 'b'] and 'a b' are the same key.

    import { LRUCache } from 'iso-web/lru'

    const cache = new LRUCache<string>({ max: 500 })
    cache.set('key', 'value', { ttl: 60 })
    cache.get('key') // 'value'
    import { resolve } from 'iso-web/doh'
    import { LRUCache } from 'iso-web/lru'

    const cache = new LRUCache({ max: 5000 })
    const { result } = await resolve('example.com', 'A', { cache })

    Type Parameters

    • V = unknown
    Index
    • Type Parameters

      • V = unknown

      Parameters

      • Optionaloptions: { max?: number } = {}
        • Optionalmax?: number

          Maximum number of entries, defaults to 1000

      Returns LRUCache<V>

    • get size(): number

      Number of entries, including expired ones not yet evicted

      Returns number

    • Parameters

      • key: string | string[]

      Returns void

    • Parameters

      • key: string | string[]

      Returns V | undefined

    • Parameters

      • key: string | string[]
      • value: V
      • Optionaloptions: { ttl?: number } = {}

        ttl in seconds, values not greater than 0 are not cached. Without a ttl the entry only leaves the cache when evicted.

      Returns LRUCache<V>