Skip to main content

CacheConfig

Config component for useCache. The useLoad hook use the cache instance configured by CacheConfig.

API

import React from "react";
import { CacheConfig } from "@lilib/hooks";
import App from "./App";

function Root() {
return (
<CacheConfig {...}>
<App />
</CacheConfig>
);
}

Props

PropertyTypeDescriptionDefault
globalbooleanUse global cache instancefalse
inheritbooleanInherit parent configfalse
cacheCacheInterfaceA cache instance implements the CacheInterfaceMemoryCache
cacheTimenumberDefault cache time300000
cacheSyncboolean | { set?: boolean; delete?: boolean }Sync cache datafalse
fallbackReactNodeFallback ui when cache is not ready-

CacheInterface

interface CacheInterface {
has(key: any): boolean;
get(key: any): any;
getCacheTimestamp(key: any): number | undefined;
set(key: any, data: any, options?: { cacheTime?: number }): any;
delete(key: any): any;
isReady(): boolean;
once(name: "ready", listener: () => void): any;
off(name: "ready", listener: () => void): any;
for(key: any): {
on(name: "set" | "delete", listener: (data: any) => void): any;
off(name: "set" | "delete", listener: (data: any) => void): any;
};
}

CacheConfig.Context

A React context object that can be used in class component.

CacheConfig.useConfig

A hook returns a config object.

import React from "react";
import { CacheConfig } from "@lilib/hooks";

function Example() {
const config = CacheConfig.useConfig();
...
}