/** * Remove a CacheEntry from linked list */ protected void removeEntry(CacheEntry entry) { if (entry == _first) { _first = entry.getNext(); } if (_last == entry) { _last = entry.getPrevious(); } CacheEntry previous = entry.getPrevious(); CacheEntry next = entry.getNext(); if (previous != null) { previous.setNext(next); } if (next != null) { next.setPrevious(previous); } entry.setPrevious(null); entry.setNext(null); }
public V nextElement() { CacheEntry entry = elements.next(); return (V)entry.getValue(); } }
/** * Add a CacheEntry. Entry goes at the end of the list. */ protected void addEntry(CacheEntry entry) { if (_first == null) { _first = entry; _last = entry; } else { _last.setNext(entry); entry.setPrevious(_last); _last = entry; } }
/** * 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); } }
/** * 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; }
/** * 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 ); } }
/** * 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; }
/** * Add a CacheEntry. Entry goes at the end of the list. */ protected void addEntry( CacheEntry entry ) { if ( first == null ) { first = entry; last = entry; } else { last.setNext( entry ); entry.setPrevious( last ); last = 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()); } }
/** * Remove a CacheEntry from linked list, and relink the * remaining element sin the list. */ protected void removeEntry( CacheEntry entry ) { if ( entry == first ) { first = entry.getNext(); if ( first != null ) { first.setPrevious( null ); } } else if ( last == entry ) { last = entry.getPrevious(); if ( last != null ) { last.setNext( null ); } } else { entry.getPrevious().setNext( entry.getNext() ); entry.getNext().setPrevious( entry.getPrevious() ); } }
/** * 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 ); } }
/** * 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; }
/** * Add a CacheEntry. Entry goes at the end of the list. */ protected void addEntry( CacheEntry entry ) { if ( first == null ) { first = entry; last = entry; } else { last.setNext( entry ); entry.setPrevious( last ); last = entry; } }
public V nextElement() { CacheEntry entry = elements.next(); return ( V ) entry.getValue(); } }
/** * 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() ); } }
/** * Remove a CacheEntry from linked list, and relink the * remaining element sin the list. */ protected void removeEntry( CacheEntry entry ) { if ( entry == first ) { first = entry.getNext(); if ( first != null ) { first.setPrevious( null ); } } else if ( last == entry ) { last = entry.getPrevious(); if ( last != null ) { last.setNext( null ); } } else { entry.getPrevious().setNext( entry.getNext() ); entry.getNext().setPrevious( entry.getPrevious() ); } }
public Object nextElement() { CacheEntry entry = (CacheEntry)_enum.nextElement(); return entry.getValue(); } }
/** * 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; } }
/** * 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; } }