Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.169/page_editor/app/utils/useCache",["module","exports","require","@liferay/frontend-js-react-web","liferay!frontend-js-react-web$react","../contexts/StoreContext","./cache"],(function(e,t,a){window;Object.defineProperty(t,"__esModule",{value:!0}),t.default=function useCache({fetcher:e,key:t}){const a=(0,n.useDispatch)(),s=(0,o.getCacheKey)(t),{data:d}=(0,o.getCacheItem)(s),i=function useTriggerRender(){const e=(0,r.useIsMounted)(),[,t]=(0,c.useState)(!1);return(0,c.useCallback)((()=>{e()&&t((e=>!e))}),[e])}();return(0,c.useEffect)((()=>{const{data:t,loadPromise:a,status:r}=(0,o.getCacheItem)(s);if(!t&&s&&r!==o.CACHE_STATUS.loading){const t=e();(0,o.setCacheItem)({key:s,loadPromise:t,status:o.CACHE_STATUS.loading}),t.then((e=>{e.error?(0,o.deleteCacheItem)(s):(0,o.setCacheItem)({data:e,key:s,status:o.CACHE_STATUS.saved}),i()})).catch((()=>(0,o.deleteCacheItem)(s)))}else r===o.CACHE_STATUS.loading&&a&&a.then(i)}),[s,a,e,i]),d};var r=a("@liferay/frontend-js-react-web"),c=a("liferay!frontend-js-react-web$react"),n=a("../contexts/StoreContext"),o=a("./cache")}));
//# sourceMappingURL=useCache.js.map