Class CachedObject<T>

java.lang.Object
org.apache.fulcrum.cache.CachedObject<T>
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
RefreshableCachedObject

public class CachedObject<T> extends Object implements Serializable
Wrapper for an object you want to store in a cache for a period of time.
Version:
$Id$
Author:
Dave Bryson, Henning P. Schmiedehausen, Eric Pugh
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected long
    When the object is created.
    static final int
    Cache the object with the Default TTL
    static final int
    Do not expire the object
  • Constructor Summary

    Constructors
    Constructor
    Description
    CachedObject(T object)
    Constructor; sets the object to expire in the default time (30 minutes).
    CachedObject(T object, long expires)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the cached object.
    long
    Returns the creation time for the object.
    long
    Returns the expiration time for the object.
    boolean
    Is the object stale?
    void
    setExpires(long expires)
    Set the expiration interval for the object.
    void
    setStale(boolean stale)
    Set the stale status for the object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT

      public static final int DEFAULT
      Cache the object with the Default TTL
      See Also:
    • FOREVER

      public static final int FOREVER
      Do not expire the object
      See Also:
    • created

      protected long created
      When the object is created.
  • Constructor Details

    • CachedObject

      public CachedObject(T object)
      Constructor; sets the object to expire in the default time (30 minutes).
      Parameters:
      object - The object you want to cache.
    • CachedObject

      public CachedObject(T object, long expires)
      Constructor.
      Parameters:
      object - The object to cache.
      expires - How long before the object expires, in ms, e.g. 1000 = 1 second.
  • Method Details

    • getContents

      public T getContents()
      Returns the cached object.
      Returns:
      The cached object.
    • getCreated

      public long getCreated()
      Returns the creation time for the object.
      Returns:
      When the object was created.
    • getExpires

      public long getExpires()
      Returns the expiration time for the object.
      Returns:
      When the object expires.
    • setExpires

      public void setExpires(long expires)
      Set the expiration interval for the object.
      Parameters:
      expires - Expiration interval in millis ( 1 second = 1000 millis)
    • setStale

      public void setStale(boolean stale)
      Set the stale status for the object.
      Parameters:
      stale - Whether the object is stale or not.
    • isStale

      public boolean isStale()
      Is the object stale?
      Returns:
      True if the object is stale.