ozone core API

org.ozoneDB.core.storage
Class FixedSizeCache

java.lang.Object
  extended byorg.ozoneDB.core.storage.AbstractTrimmingCache
      extended byorg.ozoneDB.core.storage.FixedSizeCache
All Implemented Interfaces:
Cache, PropertyConfigurable, TrimmingCache

public class FixedSizeCache
extends AbstractTrimmingCache
implements PropertyConfigurable

A cache with a fixed maximum number of objects in it. This cache grows until it has reached its maximum, which can be set by maxCapacity. Once that maximum has been reached, the least recently used object is thrown away when a new object is put in the cache. This cache has, next to that maximum number of elements, also a maximum time an element will remain in this cache. If that time has expired the element will be removed from this cache also. Reinserting an element (using the same key) causes the time for that element to be reset.

Note: every instance creates its own thread for asynchronous removal of items past their 'best before' time. The trimmed() method on the TrimHandler is often but not always called asynchronously from that thread.

Version:
$Id: FixedSizeCache.java,v 1.4 2004/03/23 10:14:14 leomekenkamp Exp $
Author:
Leo Mekenkamp (mind the anti sp@m)

Nested Class Summary
private  class FixedSizeCache.OurMap
           
 
Nested classes inherited from class org.ozoneDB.core.storage.TrimmingCache
TrimmingCache.TrimHandler
 
Field Summary
static PropertyInfo INITIALCAPACITY
           
static PropertyInfo LOADFACTOR
           
private static java.util.logging.Logger log
           
private  java.util.Map map
           
private  int maxCapacity
           
static PropertyInfo MAXCAPACITY
           
 
Fields inherited from class org.ozoneDB.core.storage.AbstractTrimmingCache
 
Constructor Summary
FixedSizeCache(java.util.Properties properties, java.lang.String prefix)
           
 
Method Summary
 java.util.Map copyToMap()
           
 java.lang.Object get(java.lang.Object key)
          Returns the object in this cache for the given key.
private  java.util.Map getMap()
           
 int getMaxCapacity()
           
 java.util.Collection getPropertyInfos()
          Returns a Collection with all the properties this instance supports.
 void put(java.lang.Object key, java.lang.Object value)
          Puts an object into the cache, along with its identifying key.
 java.lang.Object remove(java.lang.Object key)
          Returns the object in this cache for the given key and removes it from the cache.
 void setMaxCapacity(int maxCapacity)
           
 int size()
           
private  void trim()
           
 
Methods inherited from class org.ozoneDB.core.storage.AbstractTrimmingCache
getPrefix, getSynchronizer, getTrimHandler, setSynchronizer, setTrimHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.ozoneDB.core.storage.PropertyConfigurable
getPrefix
 

Field Detail

log

private static final java.util.logging.Logger log

MAXCAPACITY

public static final PropertyInfo MAXCAPACITY

INITIALCAPACITY

public static final PropertyInfo INITIALCAPACITY

LOADFACTOR

public static final PropertyInfo LOADFACTOR

maxCapacity

private int maxCapacity

map

private java.util.Map map
Constructor Detail

FixedSizeCache

public FixedSizeCache(java.util.Properties properties,
                      java.lang.String prefix)
Throws:
ConfigurationException
Method Detail

getMap

private java.util.Map getMap()

setMaxCapacity

public final void setMaxCapacity(int maxCapacity)

getMaxCapacity

public final int getMaxCapacity()

getPropertyInfos

public java.util.Collection getPropertyInfos()
Description copied from interface: PropertyConfigurable

Returns a Collection with all the properties this instance supports.

Specified by:
getPropertyInfos in interface PropertyConfigurable
Overrides:
getPropertyInfos in class AbstractTrimmingCache

put

public void put(java.lang.Object key,
                java.lang.Object value)
Description copied from interface: Cache
Puts an object into the cache, along with its identifying key.

Specified by:
put in interface Cache

trim

private void trim()

copyToMap

public java.util.Map copyToMap()
Specified by:
copyToMap in interface Cache

get

public java.lang.Object get(java.lang.Object key)
Description copied from interface: Cache
Returns the object in this cache for the given key.

Specified by:
get in interface Cache

remove

public java.lang.Object remove(java.lang.Object key)
Description copied from interface: Cache
Returns the object in this cache for the given key and removes it from the cache.

Specified by:
remove in interface Cache

size

public int size()
Specified by:
size in interface Cache

ozone core API

Copyright (C) The Ozone Database Project - www.ozone-db.org. All rights reserved.