Overview | Package | Class | Tree | Deprecated | Index | Help
| © 2003 BEA Systems, Inc.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.bea.p13n.cache
Interface Cache

All Superinterfaces:
  CacheDefaults, CacheStats, ReloadableCache

public interface Cache
extends CacheDefaults, CacheStats, ReloadableCache

The main interface for the cache. Provides methods to add, access, and remove entries from a cache.

Keys may be any object, although it is suggested that Strings or lightweight Serializable objects be used. In order to receive notifications to invalidate a particular key in the cache (from other nodes of a cluster or from Admin server), the key must be Serializable (so it can be transmitted between servers). Such keys must also have properly implemented equals() and hashcode() methods.

CAUTION: The cache data structure does not itself provide immutability of its values. In other words, it returns references to its actual objects. It is recommended that those values protect themselves from change unless that change is actually desired - remember these objects will eventually expire from the Cache.

Field Summary

Fields inherited from interface com.bea.p13n.cache.CacheDefaults
`DEFAULT_ENABLED, DEFAULT_MAX_ENTRIES, DEFAULT_TTL, MAX_ENTRIES_MAX, TTL_NEVER_EXPIRE`

Method Summary
`void` | `clear()` Remove all elements from the cache.
`boolean` | `containsKey(Object key)` Determines if an entry exists in the cache.
`Set` | `entrySet()` Access the values of the key/value pair of the Cache.
`Object` | `get(Object key)` Retrieve an entry in the Cache.
`int` | `getMaxEntries()` Get the max number of entries the cache can have.
`String` | `getName()` Get cache name.
`long` | `getTtl()` Get the time-to-live, in milliseconds, of entries for the cache.
`boolean` | `isEnabled()` Is the cache enabled?
`Set` | `keySet()` Access the keys of the key/value pair of the Cache.
`Object` | `put(Object key, Object value)` Put a value into the cache.
`Object` | `put(Object key, Object value, long ttl)` Put a value into the cache, with a specific time-to-live.
`Object` | `remove(Object key)` Removes a single entry from the Cache if it exists.
`void` | `setEnabled(boolean newEnabled)` Set enabled mode of cache.
`void` | `setMaxEntries(int maxEntries)` Set the max number of items the cache can have.
`void` | `setTtl(long timeToLive)` Set the default time-to-live for all elements in cache.
`int` | `size()` Size of the cache.
`String` | `toString()` Describes the attributes of the cache.

Methods inherited from interface com.bea.p13n.cache.CacheStats
`getHitCount, getHitRate, getMissCount, resetStats`

Methods inherited from interface com.bea.p13n.cache.ReloadableCache
`getReloader, put, put, reload, setReloader, unsetReloader`

Method Detail

### put

    public Object put(Object key,
                      Object value)

  Put a value into the cache.

  Neither the key nor the value can be null

  Parameters:
    `key` - the key of the entry to create
    `value` - the value to associate with the key
  Returns:
    `Object` the previous value for the key

### put

    public Object put(Object key,
                      Object value,
                      long ttl)

  Put a value into the cache, with a specific time-to-live.

  Neither the key nor the value can be null

  Parameters:
    `key` - the key of the entry to create
    `value` - the value to associate with the key
    `ttl` - time-to-live, in milliseconds, of the object. This ttl overrides the default ttl for the cache, and applies only to this object.
  Returns:
    `Object` the previous value for the key

### get

    public Object get(Object key)

  Retrieve an entry in the Cache. Returns null if the entry does not exist or has expired or if the cache is not enabled. Otherwise, it returns the Value associated with the key and moves the entry to the top of the LRU list (making it the most recently used object.

  Parameters:
    `key` - The key of a key/value pair to retrieve from the cache.
  Returns:
    `Object` the value of the key/value pair asslciated with the key, or null if the entry does not exist or has expired.

### clear

    public void clear()

  Remove all elements from the cache.

### remove

    public Object remove(Object key)

  Removes a single entry from the Cache if it exists.

  Parameters:
    `key` - The key of a key/value pair to remove from the cache.
  Returns:
    The object that was removed, or null if object did not exist.

### size

    public int size()

  Size of the cache. This returns the size of the internal map. This may or may not match the size of the collection returned from the values method. The values method will strip out all expired values.

  Returns:
    `int` The number of entries in the cache.

### keySet

    public Set keySet()

  Access the keys of the key/value pair of the Cache. Values that have expired are not included in this set.

  Returns:
    `Set` The set of keys in the key/value entries of the cacbe.

### entrySet

    public Set entrySet()

  Access the values of the key/value pair of the Cache. Values that have expired are not included in this set.

  Returns:
    `Set` The set of values of the key/value pair of the Cache.

### isEnabled

    public boolean isEnabled()

  Is the cache enabled?

  Returns:
    `boolean`, true if it is enabled, flase otherwise.

### setEnabled

    public void setEnabled(boolean newEnabled)

  Set enabled mode of cache. Disabling the cache will flush the cache and cause fetch, add, and remove to do nothing.

  Parameters:
    `newEnabled` - true to enable the cache, false to disable the cache.

### containsKey

    public boolean containsKey(Object key)

  Determines if an entry exists in the cache.

  Parameters:
    `key` - The key of a key/value pair to check for existence in the cache.
  Returns:
    `boolean` true if the object associated with that key exists in the cache, false otherwise.

### getTtl

    public long getTtl()

  Get the time-to-live, in milliseconds, of entries for the cache. Unless specified for each entry individually, the time-to-live is set upon creation of the cache and applies to all entries in the cache.

  Returns:
    the cache's time-to-live value in milliseconds

### setTtl

    public void setTtl(long timeToLive)

  Set the default time-to-live for all elements in cache. Note that using a value of TTL_NEVER_EXPIRE, means elements will never expire.

### getMaxEntries

    public int getMaxEntries()

  Get the max number of entries the cache can have. The cache uses a LRU strategy, so that it will never contain more than maxEntries entries.

  Returns:
    the maximum number of entries of the cache

### setMaxEntries

    public void setMaxEntries(int maxEntries)

  Set the max number of items the cache can have. Because the cache implements a LRU (least-recently-used) strategy, the maximum allowed value for this is defined in CacheDefaults.MAX_ENTRIES_MAX.

  Parameters:
    `maxEntries` - the maximum size of the cache

### getName

    public String getName()

  Get cache name. Each cache has a unique name, and is referenced by that name. The CacheFactory maintains a collection of cache objects, and the cache name represents the key in the key/value pair in the collection.

  Returns:
    The cache name

### toString

    public String toString()

  Describes the attributes of the cache.

  Overrides:
    `toString` in class `Object`
  Returns:
    the attributes of the cache.

Overview | Package | Class | Tree | Deprecated | Index | Help
| © 2003 BEA Systems, Inc.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003 BEA Systems, Inc. All Rights Reserved