Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.132/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({fetcher:e,key:t}){const a=(0,c.useDispatch)(),s=(0,n.getCacheKey)(t),{data:d}=(0,n.getCacheItem)(s),i=function(){const e=(0,r.useIsMounted)(),[,t]=(0,o.useState)(!1);return(0,o.useCallback)((()=>{e()&&t((e=>!e))}),[e])}();return(0,o.useEffect)((()=>{const{data:t,loadPromise:a,status:r}=(0,n.getCacheItem)(s);if(!t&&s&&r!==n.CACHE_STATUS.loading){const t=e();(0,n.setCacheItem)({key:s,loadPromise:t,status:n.CACHE_STATUS.loading}),t.then((e=>{e.error?(0,n.deleteCacheItem)(s):(0,n.setCacheItem)({data:e,key:s,status:n.CACHE_STATUS.saved}),i()})).catch((()=>(0,n.deleteCacheItem)(s)))}else r===n.CACHE_STATUS.loading&&a&&a.then(i)}),[s,a,e,i]),d};var r=a("@liferay/frontend-js-react-web"),o=a("liferay!frontend-js-react-web$react"),c=a("../contexts/StoreContext"),n=a("./cache")}));
//# sourceMappingURL=useCache.js.map