public void setCached(C data) { if (query.isCacheable()) { Cache cache = ccf.get(query); if (cache != null) { cache.put(new Element(getId(), data)); if (query.getHitCount() > 0 && !query.isEternal()) { CacheStats cs = getCacheStats(); ccf.createCacheJob(this, cs.getExpTime()); } if (log.isDebugEnabled()) { log.debug(String.format("Element %s put into %s cache", getId(), query.getQid())); } } } }
@SuppressWarnings("unchecked") public C getCached() { if (query.isCacheable()) { Cache cache = ccf.get(query); if (cache == null) { if (log.isDebugEnabled()) { log.debug(String.format("Cache for %s not found", this)); } } else { if (log.isDebugEnabled()) { log.debug(String.format("Cache for %s found", this)); } if (cache.isKeyInCache(getId())) { Element el = cache.get(getId()); boolean expired = (el == null || el.isExpired()); if (log.isDebugEnabled()) { log.debug( String.format( "Element %d found in %s cache (expired = %s)", getId(), query.getQid(), expired)); } if (el != null && !expired) { return (C) el.getObjectValue(); } } else { if (log.isDebugEnabled()) { log.debug(String.format("Element %d not found in %s cache", getId(), query.getQid())); } } } } return (C) null; }
public CacheStats getCacheStats() { CacheStats cs = new CacheStats(); if (query.isCacheable()) { Cache cache = ccf.get(query); if (cache != null) { if (cache.isKeyInCache(getId())) { Element el = cache.get(getId()); cs.setExpired(el == null || el.isExpired()); if (el != null && !cs.isExpired()) { cs.setLastUpdate(el.getLastUpdateTime()); cs.setExpTime(el.getExpirationTime()); cs.setHitCount(el.getHitCount()); } } } } return cs; }