Cache service
Backend
Brush is shipped with a simple yet useful cache service which enforces industry-standard caching interface.
Loading the cache service
Section titled “Loading the cache service”Just import the cache service in your file:
import Cache from "relative/path/to/_brush/cache";Create a cache key
Section titled “Create a cache key”Create a cache key for the item you wish to store / retrieve from cache.
const cacheKey = "some_unique_cache_key";Check cache entry
Section titled “Check cache entry”const hasItem = Cache.has(cacheKey);Store cache
Section titled “Store cache”const someString = "Hello world";Cache.set<string>.set(cacheKey, someString);
const someObject = {firstname: "John", lastname: "Doe"}Cache.set<Record<string, string>>.set(cacheKey, someObject);Get cache entry
Section titled “Get cache entry”const someString = Cache.set<string>.get(cacheKey);const someObject = Cache.set<Record<string, string>>.get(cacheKey);Delete cache entry
Section titled “Delete cache entry”Cache.delete(cacheKey);Flush cache
Section titled “Flush cache”Cache.clear();