In-memory cache that keeps at most max entries, evicting the least recently used one first. Entries can expire after a ttl.
max
ttl
Array keys are joined with a space, so ['a', 'b'] and 'a b' are the same key.
['a', 'b']
'a b'
import { LRUCache } from 'iso-web/lru'const cache = new LRUCache<string>({ max: 500 })cache.set('key', 'value', { ttl: 60 })cache.get('key') // 'value' Copy
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 }) Copy
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 })
Optional
Maximum number of entries, defaults to 1000
Number of entries, including expired ones not yet evicted
ttl in seconds, values not greater than 0 are not cached. Without a ttl the entry only leaves the cache when evicted.
In-memory cache that keeps at most
maxentries, evicting the least recently used one first. Entries can expire after attl.Array keys are joined with a space, so
['a', 'b']and'a b'are the same key.Template: V
Example
Example