/** * Creates a soft-reference based L2 cache with a {@link MRU} cache as * the internal (L1) cache. The soft reference cache uses the * default load capacity of 1.5f, which is intended to sacrifice some * performance for space. This compromise is reasonable, since all * {@link #get(Object) get( )s} first try the L1 cache anyway. The * internal MRU is given a capacity of 128 elements. */ public SoftCache() { this( new MRU( INITIAL_CAPACITY ) ); }
/** * Place entry at the end of linked list -- Most Recently Used */ protected void touchEntry( CacheEntry entry ) { if ( last == entry ) { return; } removeEntry( entry ); addEntry( entry ); }
/** * Obtain an object in the cache */ public Object get(Object key) { CacheEntry entry = (CacheEntry)_hash.get(key); if (entry != null) { touchEntry(entry); return entry.getValue(); } else { return null; } }
/** * Place an object in the cache. */ public void put(Object key, Object value) throws CacheEvictionException { CacheEntry entry = (CacheEntry)_hash.get(key); if (entry != null) { entry.setValue(value); touchEntry(entry); } else { if (_hash.size() == _max) { // purge and recycle entry entry = purgeEntry(); entry.setKey(key); entry.setValue(value); } else { entry = new CacheEntry(key, value); } addEntry(entry); _hash.put(entry.getKey(), entry); } }
/** * Remove an object from the cache */ public void remove( K key ) { CacheEntry entry = map.get( key ); if ( entry != null ) { removeEntry( entry ); map.remove( entry.getKey() ); } }
/** * Place an object in the cache. */ public void put( K key, V value ) throws CacheEvictionException { CacheEntry entry = map.get( key ); if ( entry != null ) { entry.setValue( value ); touchEntry( entry ); } else { if ( map.size() == max ) { // purge and recycle entry entry = purgeEntry(); entry.setKey( key ); entry.setValue( value ); } else { entry = new CacheEntry( key, value ); } addEntry( entry ); map.put( entry.getKey(), entry ); } }
/** * Remove an object from the cache */ public void remove( K key ) { CacheEntry entry = map.get( key ); if ( entry != null ) { removeEntry( entry ); map.remove( entry.getKey() ); } }
/** * Place an object in the cache. */ public void put( K key, V value ) throws CacheEvictionException { CacheEntry entry = map.get( key ); if ( entry != null ) { entry.setValue( value ); touchEntry( entry ); } else { if ( map.size() == max ) { // purge and recycle entry entry = purgeEntry(); entry.setKey( key ); entry.setValue( value ); } else { entry = new CacheEntry( key, value ); } addEntry( entry ); map.put( entry.getKey(), entry ); } }
/** * Creates a soft-reference based L2 cache with a {@link MRU} cache as * the internal (L1) cache. The soft reference cache uses the * default load capacity of 1.5f, which is intended to sacrifice some * performance for space. This compromise is reasonable, since all * {@link #get(Object) get( )s} first try the L1 cache anyway. The * internal MRU is given a capacity of 128 elements. */ public SoftCache() { this( new MRU( INITIAL_CAPACITY ) ); }
/** * Place entry at the end of linked list -- Most Recently Used */ protected void touchEntry( CacheEntry entry ) { if ( last == entry ) { return; } removeEntry( entry ); addEntry( entry ); }
/** * Remove an object from the cache */ public void remove(Object key) { CacheEntry entry = (CacheEntry)_hash.get(key); if (entry != null) { removeEntry(entry); _hash.remove(entry.getKey()); } }
/** * Obtain an object in the cache */ public V get( K key ) { CacheEntry entry = map.get( key ); if ( entry != null ) { touchEntry( entry ); return (V)entry.getValue(); } else { return null; } }
/** * Creates a soft-reference based L2 cache with a {@link MRU} cache as * the internal (L1) cache. The soft reference cache uses the * default load capacity of 1.5f, which is intended to sacrifice some * performance for space. This compromise is reasonable, since all * {@link #get(Object) get( )s} first try the L1 cache anyway. The * internal MRU is given a capacity of 128 elements. */ public SoftCache() { this(new MRU(INITIAL_CAPACITY)); }
/** * Place entry at the end of linked list -- Most Recently Used */ protected void touchEntry(CacheEntry entry) { if (_last == entry) { return; } removeEntry(entry); addEntry(entry); }
/** * Purge least recently used object from the cache * * @return recyclable CacheEntry */ protected CacheEntry purgeEntry() throws CacheEvictionException { CacheEntry entry = _first; // Notify policy listeners first. if any of them throw an // eviction exception, then the internal data structure // remains untouched. CachePolicyListener listener; for (int i=0; i<listeners.size(); i++) { listener = (CachePolicyListener)listeners.elementAt(i); listener.cacheObjectEvicted(entry.getValue()); } removeEntry(entry); _hash.remove(entry.getKey()); entry.setValue(null); return entry; }
/** * Obtain an object in the cache */ public V get( K key ) { CacheEntry entry = map.get( key ); if ( entry != null ) { touchEntry( entry ); return ( V ) entry.getValue(); } else { return null; } }
MRU cache = new MRU( cacheSize ); recman = new CacheRecordManager( recman, cache );
/** * Purge least recently used object from the cache * * @return recyclable CacheEntry */ protected CacheEntry purgeEntry() throws CacheEvictionException { CacheEntry entry = first; // Notify policy listeners first. if any of them throw an // eviction exception, then the internal data structure // remains untouched. CachePolicyListener listener; for ( int i = 0; i < listeners.size(); i++ ) { listener = listeners.get( i ); listener.cacheObjectEvicted( entry.getValue() ); } removeEntry( entry ); map.remove( entry.getKey() ); entry.setValue( null ); return entry; }
MRU cache = new MRU( cacheSize ); recman = new CacheRecordManager( recman, cache );
/** * Purge least recently used object from the cache * * @return recyclable CacheEntry */ protected CacheEntry purgeEntry() throws CacheEvictionException { CacheEntry entry = first; // Notify policy listeners first. if any of them throw an // eviction exception, then the internal data structure // remains untouched. CachePolicyListener listener; for ( int i = 0; i < listeners.size(); i++ ) { listener = listeners.get( i ); listener.cacheObjectEvicted( entry.getValue() ); } removeEntry( entry ); map.remove( entry.getKey() ); entry.setValue( null ); return entry; }