    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class jclass.util.JCCache

    java.lang.Object
       |
       +----jclass.util.JCCache

public class JCCache
extends Object

JCCache class implements a lightweight cache that works on any Object-based (key, value) pair. To use this cache, the key class must implement the following methods:

- public int hashCode();
- public boolean equals(Object obj);
- public String toString();

##

JCCache(int, int)
  This is the constructor for JCCache.

##

addToCache(Object, Object)
  This adds a key or item pair to the cache.
getFromCache(Object)
  This retrieves the item associated with the key from the cache.
toString()
  This converts the cache contents to a large string.

##

JCCache

     public JCCache(int bins,
                    int binsize)

  This is the constructor for JCCache. Internally, the cache is made up of a number of buckets of a certain size. As data is added to the cache, it is added to a bucket based on its hash value.

  Parameters:
    bins - the number of buckets in the cache
    binsize - the length of each bucket

##

addToCache

     public final void addToCache(Object key,
                                  Object item)

  This adds a key or item pair to the cache. If the item is already in the cache, the value is updated.

  Parameters:
    key - the key object for the cached item
    item - the item to add to the cache

getFromCache

     public final Object getFromCache(Object key)

  This retrieves the item associated with the key from the cache. If no item is found, getFromCache() returns null.

  Parameters:
    key - the key object for the cached item
  Returns:
    cached item

toString

     public final String toString()

  This converts the cache contents to a large string. This is useful only for debugging purposes.

  Returns:
    string for printing
  Overrides:
    toString in class Object

    All Packages  Class Hierarchy  This Package  Previous  Next  Index