1 import type { ReactNode } from 'react';
2 import { useEffect, useRef } from 'react';
4 import type { Cache } from '@proton/shared/lib/helpers/cache';
5 import createCache from '@proton/shared/lib/helpers/cache';
7 import CacheContext from './cacheContext';
9 interface Props<K, V> {
14 export const CacheProvider = <K, V>({ cache, children }: Props<K, V>) => {
15 const cacheRef = useRef<Cache<string, any>>(cache as any);
16 if (!cacheRef.current) {
17 cacheRef.current = createCache<string, any>();
20 const cache = cacheRef.current;
23 cache.clearListeners();
26 return <CacheContext.Provider value={cacheRef.current}>{children}</CacheContext.Provider>;