Skip to content

Cache service

Backend

Brush is shipped with a simple yet useful cache service which enforces industry-standard caching interface.

Just import the cache service in your file:

import Cache from "relative/path/to/_brush/cache";

Create a cache key for the item you wish to store / retrieve from cache.

const cacheKey = "some_unique_cache_key";
const hasItem = Cache.has(cacheKey);
const someString = "Hello world";
Cache.set<string>.set(cacheKey, someString);
const someObject = {firstname: "John", lastname: "Doe"}
Cache.set<Record<string, string>>.set(cacheKey, someObject);
const someString = Cache.set<string>.get(cacheKey);
const someObject = Cache.set<Record<string, string>>.get(cacheKey);
Cache.delete(cacheKey);
Cache.clear();