public CachePolicy createCachePolicy() { return new LRUCachePolicy(min, max); } }
public void flush() { LRUCacheEntry entry = null; while ((entry = m_list.m_tail) != null) { ageOut(entry); } }
/** * Initializes the cache, creating all required objects and initializing their * values. * @see #start * @see #destroy */ public void create() { m_map = createMap(); m_list = createList(); m_list.m_maxCapacity = m_maxCapacity; m_list.m_minCapacity = m_minCapacity; m_list.m_capacity = m_maxCapacity; } /**
public void destroy() { m_overager = null; m_resizer = null; super.destroy(); }
/** * Stops this cache thus {@link #flush}ing all cached objects. <br> * After this method is called, a call to {@link #start} will restart the cache. * @see #start * @see #destroy */ public void stop() { if (m_list != null) { flush(); } } /**
public void insert(Object key, Object obj) { try { Object versioned = versionManager.makeVersioned(obj); super.insert(key, versioned); } catch (Exception ex) { throw new RuntimeException(ex); } } }
public void insert(Object key, Object o) { if (o == null) {throw new IllegalArgumentException("Cannot insert a null object in the cache");} if (key == null) {throw new IllegalArgumentException("Cannot insert an object in the cache with null key");} if (m_map.containsKey(key)) { throw new IllegalStateException("Attempt to put in the cache an object that is already there"); } m_list.demote(); LRUCacheEntry entry = createCacheEntry(key, o); m_map.put(key, entry); m_list.promote(entry); } public void remove(Object key)
public Object get(Object key) { if (key == null) { throw new IllegalArgumentException("Requesting an object using a null key"); } LRUCacheEntry value = (LRUCacheEntry)m_map.get(key); if (value != null) { m_list.promote(value); return value.m_object; } else { cacheMiss(); return null; } } public Object peek(Object key)
public ClassReaderCache createCache() { CachePolicy policy = null; if (policyClass == TimedCachePolicy.class) policy = new TimedCachePolicy(lifetime, true, resolution); else if (policyClass == LRUCachePolicy.class) policy = new LRUCachePolicy(min, max); else { try { policy = policyClass.newInstance(); } catch(Exception e) { throw new IllegalStateException("Could not instantiate " + policyClass.getName(), e); } } try { policy.create(); policy.start(); } catch(Exception e) { throw new IllegalStateException("Error starting domain cache", e); } return new ClassReaderCache(policy); }
/** * Demotes from the cache the least used entry. <br> * If the cache is not full, does nothing. * @see #promote */ protected void demote() { if (m_capacity < 1) {throw new IllegalStateException("Can't work with capacity < 1");} if (m_count > m_maxCapacity) {throw new IllegalStateException("Cache list entries number (" + m_count + ") > than the maximum allowed (" + m_maxCapacity + ")");} if (m_count == m_maxCapacity) { LRUCacheEntry entry = m_tail; // the entry will be removed by ageOut ageOut(entry); } else {} // cache is not full, do nothing } /**
public CtClassCache createCache() { CachePolicy policy = null; if (policyClass == TimedCachePolicy.class) policy = new TimedCachePolicy(lifetime, true, resolution); else if (policyClass == LRUCachePolicy.class) policy = new LRUCachePolicy(min, max); else { try { policy = policyClass.newInstance(); } catch(Exception e) { throw new IllegalStateException("Could not instantiate " + policyClass.getName(), e); } } try { policy.create(); policy.start(); } catch(Exception e) { throw new IllegalStateException("Error starting domain cache", e); } return new CtClassCache(policy); }
protected void ageOut(LRUCachePolicy.LRUCacheEntry entry) { try { CachedPreparedStatement ws = (CachedPreparedStatement) entry.m_object; ws.agedOut(); } catch (SQLException e) { log.debug("Failed closing cached statement", e); } finally { super.ageOut(entry); } }