Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.opensymphony.oscache.base
Class CacheEntry

    java.lang.Object
      com.opensymphony.oscache.base.CacheEntry

All Implemented Interfaces:
  java.io.Serializable

public class CacheEntry
extends java.lang.Object
implements java.io.Serializable

A CacheEntry instance represents one entry in the cache. It holds the object that is being cached, along with a host of information about that entry such as the cache key, the time it was cached, whether the entry has been flushed or not and the groups it belongs to.

Version:
  $Revision: 1.1 $
Author:
  Mike Cannon-Brookes, Todd Gochenour, Francois Beauregard
See Also:
  Serialized Form

Field Summary
`static int` | `INDEFINITE_EXPIRY` Specifying this as the refresh period for the `needsRefresh(int)` method will ensure an entry does not become stale until it is either explicitly flushed or a custom refresh policy causes the entry to expire.

Constructor Summary
`CacheEntry(java.lang.String key)` Construct a new CacheEntry using the key provided.
`CacheEntry(java.lang.String key, EntryRefreshPolicy policy)` Construct a CacheEntry.
`CacheEntry(java.lang.String key, EntryRefreshPolicy policy, java.lang.String[] groups)` Construct a CacheEntry.

Method Summary
`void` | `flush()` Flush the entry from cache.
`java.lang.Object` | `getContent()` Get the cached content from this CacheEntry.
`long` | `getCreated()` Get the date this CacheEntry was created.
`java.util.Set` | `getGroups()` Gets the cache groups that this cache entry belongs to.
`java.lang.String` | `getKey()` Get the key of this CacheEntry
`long` | `getLastUpdate()` Get the date this CacheEntry was last updated.
`int` | `getSize()` Get the size of the cache entry in bytes (roughly).
`boolean` | `isNew()` Indicates whether this CacheEntry is a freshly created one and has not yet been assigned content or placed in a cache.
`boolean` | `needsRefresh(int refreshPeriod)` Check if this CacheEntry needs to be refreshed.
`void` | `setContent(java.lang.Object value)` Sets the actual content that is being cached.
`void` | `setGroups(java.util.Collection groups)` Sets the cache groups for this entry
`void` | `setGroups(java.lang.String[] groups)` Sets the cache groups for this entry.
`void` | `setLastUpdate(long update)` Set the date this CacheEntry was last updated.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### INDEFINITE_EXPIRY

    public static final int INDEFINITE_EXPIRY

  Specifying this as the refresh period for the `needsRefresh(int)` method will ensure an entry does not become stale until it is either explicitly flushed or a custom refresh policy causes the entry to expire.

  See Also:
    Constant Field Values

Constructor Detail

### CacheEntry

    public CacheEntry(java.lang.String key)

  Construct a new CacheEntry using the key provided.

Parameters:
  `key` - The key of this CacheEntry

### CacheEntry

    public CacheEntry(java.lang.String key,
                      EntryRefreshPolicy policy)

  Construct a CacheEntry.

Parameters:
  `key` - The unique key for this `CacheEntry`.
  `policy` - Object that implements refresh policy logic. This parameter is optional.

### CacheEntry

    public CacheEntry(java.lang.String key,
                      EntryRefreshPolicy policy,
                      java.lang.String[] groups)

  Construct a CacheEntry.

Parameters:
  `key` - The unique key for this `CacheEntry`.
  `policy` - The object that implements the refresh policy logic. This parameter is optional.
  `groups` - The groups that this `CacheEntry` belongs to. This parameter is optional.

Method Detail

### setContent

    public void setContent(java.lang.Object value)

  Sets the actual content that is being cached. Wherever possible this object should be `Serializable`, however it is not an absolute requirement when using a memory-only cache. Being `Serializable` allows `PersistenceListener`s to serialize the cache entries to disk or database.

  Parameters:
    `value` - The content to store in this CacheEntry.

### getContent

    public java.lang.Object getContent()

  Get the cached content from this CacheEntry.

  Returns:
    The content of this CacheEntry.

### getCreated

    public long getCreated()

  Get the date this CacheEntry was created.

  Returns:
    The date this CacheEntry was created.

### setGroups

    public void setGroups(java.lang.String[] groups)

  Sets the cache groups for this entry.

  Parameters:
    `groups` - A string array containing all the group names

### setGroups

    public void setGroups(java.util.Collection groups)

  Sets the cache groups for this entry

  Parameters:
    `groups` - A collection containing all the group names

### getGroups

    public java.util.Set getGroups()

  Gets the cache groups that this cache entry belongs to. These returned groups should be treated as immuatable.

  Returns:
    A set containing the names of all the groups that this cache entry belongs to.

### getKey

    public java.lang.String getKey()

  Get the key of this CacheEntry

  Returns:
    The key of this CacheEntry

### setLastUpdate

    public void setLastUpdate(long update)

  Set the date this CacheEntry was last updated.

  Parameters:
    `update` - The time (in milliseconds) this CacheEntry was last updated.

### getLastUpdate

    public long getLastUpdate()

  Get the date this CacheEntry was last updated.

  Returns:
    The date this CacheEntry was last updated.

### isNew

    public boolean isNew()

  Indicates whether this CacheEntry is a freshly created one and has not yet been assigned content or placed in a cache.

  Returns:
    `true` if this entry is newly created

### getSize

    public int getSize()

  Get the size of the cache entry in bytes (roughly).

  Currently this method only handles `String`s and `ResponseContent` objects.``

  Returns:
    The approximate size of the entry in bytes, or -1 if the size could not be estimated.

### flush

    public void flush()

  Flush the entry from cache. note that flushing the cache doesn't actually remove the cache contents it just tells the CacheEntry that it needs a refresh next time it is asked this is so that the content is still there for a .

### needsRefresh

    public boolean needsRefresh(int refreshPeriod)

  Check if this CacheEntry needs to be refreshed.

  Parameters:
    `refreshPeriod` - The period of refresh (in seconds). Passing in `INDEFINITE_EXPIRY` will result in the content never becoming stale unless it is explicitly flushed, or expired by a custom `EntryRefreshPolicy`. Passing in 0 will always result in a refresh being required.
  Returns:
    Whether or not this CacheEntry needs refreshing.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| See www.opensymphony.com for more information.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD