velo-org / velo

A high-performance caching library for Deno. Supports LRU, LFU, ARC, and TinyLFU.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Loader for cache

herzogmatthias opened this issue · comments

Adapt the .build() method to take an optional loader function as argument. This function generates a value for given key. The value is loaded when the key is not present in the cache.

const loader = (key: string) => {
  return new Person(...);
}

const cache = Velo.builder().build<string, Person>(loader);

cache.get('323') // not in the cache, but loader('323') is called to generate the value