Overview | Package | Class | Tree | Deprecated | Index | Help
| Copyright © 2000, 2009, Oracle and/or its affiliates. All rights reserved.
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.

Cache instances are obtained from the `CacheFactory`.

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

    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

    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

    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

    void clear()

  Remove all elements from the cache. For a cluster-aware flush or clear of a cache, see `CacheFactory.flush(String)`.

### remove

    Object remove(Object key)

  Removes a single entry from the Cache if it exists. For a cluster-aware flush or removal of cached items, see `CacheFactory.flush(String, java.io.Serializable)`.

  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

    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

    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

    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

    boolean isEnabled()

  Is the cache enabled?

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

### setEnabled

    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

    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

    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

    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.

  Parameters
    `timeToLive` - the default time to live for items in this cache , in milliseconds

### getMaxEntries

    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

    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

    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

    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
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000, 2009, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.