'use strict';
import { LRUCache } from 'lru-cache';
import { isDev } from '../../lib/environments.js';
import { isObject, isFunction, isString, isNumber, isBoolean } from '../../types/ensure-type.js';
import { createError } from '../../errors/errors.js';
import { booleanStringValues } from '../../../base-repo/constants/type-string-values.js';

var __defProp=Object['defineProperty'],__name=(_0x3c4905,_0x36989d)=>__defProp(_0x3c4905,'name',{'value':_0x36989d,'configurable':!![]});function setMemoryCache(_0x12ce9b,_0x499ee3,_0x4e76d3){const _0x3961e4={};if(_0x4e76d3?.['absoluteExpirationRelativeToNowSeconds']!==void(0xe*0x278+0x2d7*0x5+-0x56b*0x9)){const _0x397b1c=_0x4e76d3['absoluteExpirationRelativeToNowSeconds']??(0x6f0+0x85e+-0x1e6*0x8)*(0x8c*0x32+-0x2*0xbf5+0x199*-0x2);_0x3961e4['ttl']=_0x397b1c*(-0x63*-0x29+0x945+-0x7*0x308);}else {if(_0x4e76d3?.['slidingExpirationSeconds']!==void(-0x2017+0x1207+0xe10)){const _0x8dd90d=_0x4e76d3['slidingExpirationSeconds'];_0x3961e4['ttl']=_0x8dd90d*(-0xd*0x1aa+0x2107+-0x3*0x27f);}}const _0x1f97b0=isObject(_0x499ee3)||isFunction(_0x499ee3)?_0x499ee3:formatCacheValue(_0x499ee3);memoryCache['set'](_0x12ce9b,_0x1f97b0,_0x3961e4);}__name(setMemoryCache,'setMemoryCache');function tryGetFromMemoryCache(_0x5e7578){return getMemoryCache(_0x5e7578);}__name(tryGetFromMemoryCache,'tryGetFromMemoryCache');function removeFromMemoryCache(_0x5171a3){memoryCache['delete'](_0x5171a3);}__name(removeFromMemoryCache,'removeFromMemoryCache');function memoryCacheHasKey(_0x5663e4){return memoryCache['has'](_0x5663e4);}__name(memoryCacheHasKey,'memoryCacheHasKey');function clearPermissionMemoryCache(_0x4a7ea6){const _0x47084d=Array['from'](memoryCache['keys']())['filter'](_0x36465e=>_0x4a7ea6['some'](_0x4dfb24=>_0x36465e['startsWith'](_0x4dfb24)));_0x47084d['forEach'](removeFromMemoryCache);}__name(clearPermissionMemoryCache,'clearPermissionMemoryCache');function formatCacheValue(_0x4cf9b4){let _0x1fb606;if(isString(_0x4cf9b4))_0x1fb606=_0x4cf9b4;else {if(isNumber(_0x4cf9b4)||isBoolean(_0x4cf9b4))_0x1fb606=_0x4cf9b4['toString']();else {if(isObject(_0x4cf9b4))_0x1fb606=JSON['stringify'](_0x4cf9b4);else throw createError('Unexpected\x20type\x20for\x20value:\x20'+typeof _0x4cf9b4);}}return _0x1fb606;}__name(formatCacheValue,'formatCacheValue');function parseCacheValue(_0x57abb0){let _0x4d9ed6;if(!_0x57abb0)_0x4d9ed6=void(0x2315*0x1+-0x20a5+-0x270);else {if(isObject(_0x57abb0)||isFunction(_0x57abb0))_0x4d9ed6=_0x57abb0;else {if(_0x57abb0===booleanStringValues['true'])_0x4d9ed6=!![];else {if(_0x57abb0===booleanStringValues['false'])_0x4d9ed6=![];else {if(!isNaN(+_0x57abb0))_0x4d9ed6=+_0x57abb0;}}}}return _0x4d9ed6;}__name(parseCacheValue,'parseCacheValue');function getMemoryCache(_0x98acd9){return parseCacheValue(memoryCache['get'](_0x98acd9));}__name(getMemoryCache,'getMemoryCache');const memoryCache=((()=>{if(isDev())return globalThis['_memoryCache']??=createMemoryCache(),globalThis['_memoryCache'];return createMemoryCache();})());function createMemoryCache(){return new LRUCache({'max':0x186a0});}__name(createMemoryCache,'createMemoryCache');

export { clearPermissionMemoryCache, formatCacheValue, memoryCacheHasKey, parseCacheValue, removeFromMemoryCache, setMemoryCache, tryGetFromMemoryCache };
