/*         -------- CACHE HELPERS ---------
495969
function applyEventStrategy(strategy, event) {
  const request = event.request;
  switch (strategy.type) {
    case 'offline-only':
      return fetchAndCache(request, strategy)().catch(getFromCache(request));
    case 'fallback-only':
      return fetchAndCache(request, strategy)().then(fallbackToCache(request));
    case 'prefer-cache':
      return getFromCache(request)().catch(fetchAndCache(request, strategy));
    case 'race':
      return getFromFastest(request, strategy)();
    default:
      return Promise.reject(`Strategy not supported: ${strategy.type}`);
  }
}
927746
function cacheGet(key, options) {
    if (shouldCache(options)) {
      return;
    }

    if (self.options.cache === 'memory') {
      return self.cache[key];
    }

    return self.options.cache.get(key);
  }
616320
protected void putToCache(String cacheName, String key, Object value) {
        putToCache(cacheName, key, value, 0);
    }
830099
private @Nullable CacheWriterException writeAllToCacheWriter(Map<? extends K, ? extends V> map) {
    if (!configuration.isWriteThrough() || map.isEmpty()) {
      return null;
    }
    List<Cache.Entry<? extends K, ? extends V>> entries = map.entrySet().stream()
        .map(entry -> new EntryProxy<>(entry.getKey(), entry.getValue()))
        .collect(toList());
    try {
      writer.writeAll(entries);
      return null;
    } catch (CacheWriterException e) {
      entries.forEach(entry -> {
        map.remove(entry.getKey());
      });
      throw e;
    } catch (RuntimeException e) {
      entries.forEach(entry -> {
        map.remove(entry.getKey());
      });
      return new CacheWriterException("Exception in CacheWriter", e);
    }
  }
708320
public void cache(String key, Object o, int ttl, Object... args) {
        if (conf().cacheDisabled()) return;
        ICacheService cacheService = _cacheService;
        Serializable value = null == o ? "" : (o instanceof Serializable ? (Serializable) o : o.toString());
        if (args.length > 0) {
            StringBuilder sb = new StringBuilder(key);
            for (Object arg : args) {
                sb.append("-").append(arg);
            }
            key = sb.toString();
        }
        cacheService.put(key, value, ttl);
    }
1298317
void cache(ManagedObject managedObject) {
        // Make a local reference to cachedManagedObjects in case it is changing, there is a risk that 
        // the same slot in cachedMangedObjects will be used twice, in that case the Object is not 
        // cached and will be read again when referenced.
        java.lang.ref.SoftReference[] localCachedManagedObjects = cachedManagedObjects;
        int localICache = iCache++;
        if (localICache >= localCachedManagedObjects.length) {
            iCache = 0;
            localICache = 0;
        }

        localCachedManagedObjects[localICache] = new java.lang.ref.SoftReference(managedObject);
        managedObject.objectStoreCacheIndex = localICache;
    }
9239
private void cacheClass(ClassSource classSource, String outerClassName) {
        if (classCacheMode != UserCodeDeploymentConfig.ClassCacheMode.OFF) {
            classSourceMap.put(outerClassName, classSource);
        } else {
            ThreadLocalClassCache.store(outerClassName, classSource);
        }
    }
288764
private final synchronized CacheElement getCacheElement(String userid) {
        String m = getCacheAbbrev() + " getCacheElement() ";
        CacheElement cacheElement = null;
        String key = getKey(userid);
        logger.debug(m + "key==" + key);
        if (cache.containsKey(key)) {
            logger.debug(m + "cache already has element");
        } else {
            logger.debug(m + "cache does not have element; create and put");
            CacheElement itemtemp =
                    new CacheElement(userid, getCacheId(), getCacheAbbrev());
            cache.put(key, itemtemp);
        }
        cacheElement = (CacheElement) cache.get(key);
        if (cacheElement == null) {
            logger.error(m + "cache does not contain element");
        } else {
            logger.debug(m + "element retrieved from cache successfully");
        }
        return cacheElement;
    }
566399
private void populateLocalCache() {
      try (CloseableIterator iterator = cache.keySet().iterator()) {
         while (iterator.hasNext()) {
            getFromCache(iterator.next(), null);
         }
      }
   }
753511
function CacheManager (options) {
  options = options || {};

  options.ttl = Number(options.ttl);
  if (isNaN(options.ttl)) options.ttl = DEFAULT_TTL;

  if (!options.store) {
    options.store = new MemoryStore();
  }
  if (typeof options.store === 'string') {
    options.store = getDefaultStore(options.store, options.storeConfig);
  }
  if (typeof options.store.get !== 'function') {
    throw new Error('store engine must implement `get` method');
  }
  if (typeof options.store.set !== 'function') {
    throw new Error('store engine must implement `set` method');
  }
  if (typeof options.store.delete !== 'function') {
    throw new Error('store engine must implement `delete` method');
  }

  debug('create: ttl=%s', options.ttl);
  this._ttl = options.ttl;
  this._store = options.store;

  this._keys = {};
  this._fuzzyKeys = [];

  this._getMethodQueue = new CallQueue();
}
664192
@Override
	public <T> void cache(final Object key, final Object object, Class<T> clas) {
		this.logger.debug("@cache v2 ");

		if (object == null && !isAllowNullable()) {
			return;
		} else {
			this.logger.debug("logging key :", key, " with object : ", object, " with Class : ", clas);
			getCachableMap(clas).put(key, object);
		}
	}
113143
private synchronized void checkCache()
    {
        Object[] pTables = m_setTableCacheList.toArray();
        for (Object objTable : pTables)
        {
            PTable pTable = (PTable)objTable;
            if (pTable.addPTableOwner(null) == 1)
            { // Not currently being used is a candidate for flushing from the cache.
                long lTimeLastUsed = pTable.getLastUsed();
                long lTimeCurrent = System.currentTimeMillis();
                if ((lTimeCurrent - lTimeLastUsed) > (this.getCacheMinutes() * 60 * 1000))
                {
                    pTable.removePTableOwner(this, true);
                    m_setTableCacheList.remove(pTable);
                }
            }
        }
    }
1123635
function fetchCache(target, cache) {
        var x,
            length = cache.length,
            curr;

        for (x = 0; x < length; x += 1) {
            curr = cache[x];
            if (curr.target === target) {
                return curr.inspect;
            }
        }

        return null;
    }
388145
public void onCacheClear(boolean memory, boolean disk) {
        final String methodName = "onCacheClear()";
        if (tc.isDebugEnabled())
            Tr.debug(tc, methodName + " cacheName=" + _sCacheName + " memory=" + memory + " disk=" + disk + " " + this);
        if (_enable && this._inMemoryCacheEntryCount != null && memory) {
            this._inMemoryCacheEntryCount.setCount(0);
        }
        if (_csmDisk != null && _csmDisk._enable && disk) {
            if (_csmDisk._objectsOnDisk != null) {
                _csmDisk._objectsOnDisk.setCount(0);
            }
            if (_csmDisk._pendingRemovalFromDisk != null) {
                _csmDisk._pendingRemovalFromDisk.setCount(0);
            }
            if (_csmDisk._dependencyIdsOnDisk != null) {
                _csmDisk._dependencyIdsOnDisk.setCount(0);
            }
            if (_csmDisk._dependencyIdsBufferedForDisk != null) {
                _csmDisk._dependencyIdsBufferedForDisk.setCount(0);
            }
            if (_csmDisk._templatesOnDisk != null) {
                _csmDisk._templatesOnDisk.setCount(0);
            }
            if (_csmDisk._templatesBufferedForDisk != null) {
                _csmDisk._templatesBufferedForDisk.setCount(0);
            }
        }
        if (this._iCacheType == TYPE_SERVLET && (memory || disk)) {
            for (Map.Entry<String, CacheStatsModule> entry : templatesPassed.entrySet()) {
                CacheStatsModule csm = entry.getValue();
                if (csm != null && csm._enable) {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                        Tr.debug(tc, "***** clear _inMemoryAndDiskCacheEntryCount for template=" + entry.getValue() + " cacheName=" + _sCacheName);
                    if (csm._inMemoryAndDiskCacheEntryCount != null) {
                        csm._inMemoryAndDiskCacheEntryCount.setCount(0);
                    }
                }
            }
        } else if (_csmObject != null && _csmObject._enable && (memory || disk)) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                Tr.debug(tc, "***** clear _inMemoryAndDiskCacheEntryCount for cacheName=" + _sCacheName);
            if (_csmObject._inMemoryAndDiskCacheEntryCount != null) {
                _csmObject._inMemoryAndDiskCacheEntryCount.setCount(0);
            }
        }
    }
627061
public final void useCache(final boolean useCache) {
        synchronized (cache) {
            this.useCache = useCache;
            logger.logDebug(getClass(), useCache ? "Enabled" : "Disabled" + " caching");

            if (!useCache) {
                clearCache();
            }
        }
    }
1017207
@Override
    public long getCacheValueSize() {
        long valuesize = -1;
        if (this.value != null) {
            Object localValue = this.value;
            valuesize = ObjectSizer.getSize(localValue);
        } else {
            if (this.serializedValue != null) {
                byte[] localSerializedValue = this.serializedValue;
                valuesize = ObjectSizer.getSize(localSerializedValue);
            }
        }

        // System.out.println("Returning cacheValueSize = " + valuesize);
        return valuesize;
    }
1003037
public void setCacheNodes(java.util.Collection<CacheNode> cacheNodes) {
        if (cacheNodes == null) {
            this.cacheNodes = null;
            return;
        }

        this.cacheNodes = new com.amazonaws.internal.SdkInternalList<CacheNode>(cacheNodes);
    }