Skip to main content

Cache Configurations

The following snippet shows the current available cache configurations options

type CacheSettings = {    /**     * Cache Settings     */    cache?: {        /**         * The Cache drier interface, defaults to plainLocalStorage         */        driver?: CacheDriverInterface;        /**         * A prefix for each key in the driver, this is useful for multi apps in same domain         */        prefix?: string;    }};

Configurations List#

The base cache config key is cache so the following table keys wil be prefixed with cache. for usage.

SyntaxTypeDefault ValueDescription
keyString``A prefix that will be appened to all cache keys, for example the prefix key is app- then when storing key name, it will be stored as app-name in the driver engine.
driverInstance Of Cache Driver InterfacePlain Local Storage DriverThe default cache driver engine that will be used by the Cache Manager, full list of drivers are here.

Example Of Usage#

shared/config.ts
import config, { ConfigList } from 'mongez/config';import { EncryptedLocalStorageDriver } from 'mongez/cache';
const settings: ConfigList = {    cache: {        prefix: 'mngz-',        driver: new EncryptedLocalStorageDriver(),    },};
config.set(settings);

The previous configurations will prefix all stored keys with mngz- and the driver engine will be the Encrypted Local Storage.

It's advisable to use the prefix key to set it to be process.env.REACT_APP_KEY_NAME suffixed with -.

shared/config.ts
import config, { ConfigList } from 'mongez/config';import { EncryptedLocalStorageDriver } from 'mongez/cache';
const settings: ConfigList = {    cache: {        prefix: process.env.REACT_APP_KEY_NAME + '-',        driver: new EncryptedLocalStorageDriver(),    },};
config.set(settings);