public void run() { if (!m_stopped) { int oldCount = 0; int newCount = 0; synchronized (m_lock) { long now = System.currentTimeMillis(); boolean timeCheck = m_lastFreeCheck < now - m_maxCacheTime; oldCount = m_decisionCache.size(); if (oldCount > 0 && (timeCheck || oldCount > m_maxEntries)) { m_lastFreeCheck = now; // perform clean up for (Iterator<CacheEntry> entries = m_decisionCache.values().iterator(); entries.hasNext();) { CacheEntry val = entries.next(); if (val == null || val.getInserted() < (now - m_maxCacheTime)) { entries.remove(); } } } newCount = m_decisionCache.size(); } if (oldCount != newCount) { if (LOG.isDebugEnabled()) { LOG.debug("hold " + newCount + " cache entries after cleanup (previous where " + oldCount + ") --- hit-count: <" + m_hitCount.get() + "> miss-count: <" + m_missCount.get() + ">"); } } } } }, 10000, 2000);
private PDPResponse lookUp(final PDPRequest req) { if (m_stopped || m_maxCacheTime < 0) { // cache disabled return null; } String key = getCacheKey(req); CacheEntry cacheEntry = null; synchronized (m_lock) { cacheEntry = m_decisionCache.get(key); } long now = System.currentTimeMillis(); PDPResponse resp = null; if (cacheEntry != null && cacheEntry.getInserted() > (now - m_maxCacheTime) && (resp = cacheEntry.getResponse()) != null) { if (LOG.isTraceEnabled()) { LOG.trace("cache hit for <" + req + "> --return--> <" + resp + ">"); } m_hitCount.incrementAndGet(); // return copy to ensure that the request object is the input param! return new PDPResponse(resp.getDecision(), req, resp.getObligations()); } m_missCount.incrementAndGet(); return null; }
private void store(final PDPRequest request, final PDPResponse resp) { if (m_stopped || m_maxCacheTime < 0) { return; } // store copy to ensure no memory leeks because of pdp responses/requests! CacheEntry entry = new CacheEntry(new PDPResponse(resp.getDecision(), new PDPRequest(new Target()), resp.getObligations())); String key = getCacheKey(request); synchronized (m_lock) { int size = m_decisionCache.size(); if (size > m_maxEntries) { // don't insert if limit is exceeded! return; } m_decisionCache.put(key, entry); } }