org.riotfamily.cachius
Class CacheItem

java.lang.Object
  extended by org.riotfamily.cachius.CacheItem
All Implemented Interfaces:
Serializable

public class CacheItem
extends Object
implements Serializable

Representation of cached item that is backed by a file. The captured HTTP headers are kept in memory and are serialized by the default java serialization mechanism. The actual content is read from a file to avoid the overhead of object deserialization on each request.

Author:
Felix Gnass
See Also:
Serialized Form

Constructor Summary
protected CacheItem(CacheEntry entry, File cacheDir)
          Creates a new CacheItem in the specified directory.
 
Method Summary
 void clear()
           
protected  void delete()
           
 boolean exists()
          Checks whether the cache file exists, is a regular file and any data has been ever written into it.
protected  File getDir()
           
 Headers getHeaders()
           
 Set<File> getInvolvedFiles()
           
 long getLastFileModification()
          Returns the most recent modification date of the involved files.
 long getLastModified()
          Returns the last modification time.
 OutputStream getOutputStream()
           
 Map<String,String> getProperties()
          Returns the properties.
 int getSize()
          Returns the size of the cached data in bytes.
 Set<String> getTags()
          Returns the item's tags.
 Writer getWriter()
           
 void gzipContent()
           
 void invalidate()
          Invalidates the item.
 boolean isExpired()
           
 boolean isInvalidated()
           
 void setContentType(String contentType)
          Sets the Content-Type.
 void setCookies(Cookies cookies)
          Sets cookies.
 void setHeaders(Headers headers)
          Sets HTTP headers.
 void setInvolvedFiles(Set<File> files)
           
 void setLastModified(long lastModified)
          Sets the last modification time.
 void setProperties(Map<String,String> properties)
          Sets shared properties.
 void setSetContentLength(boolean setContentLength)
          Sets whether a Content-Length header should be set.
 void setTags(Set<String> tags)
          Sets tags which can be used to look up the item for invalidation.
 void setTimeToLive(long ttl)
           
 String toString()
           
 void writeTo(HttpServletResponse response)
           
 void writeTo(OutputStream out)
           
 void writeTo(Writer out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CacheItem

protected CacheItem(CacheEntry entry,
                    File cacheDir)
             throws IOException
Creates a new CacheItem in the specified directory.

Throws:
IOException
Method Detail

setTags

public void setTags(Set<String> tags)
Sets tags which can be used to look up the item for invalidation.


getTags

public Set<String> getTags()
Returns the item's tags.


setInvolvedFiles

public void setInvolvedFiles(Set<File> files)

getInvolvedFiles

public Set<File> getInvolvedFiles()

getLastFileModification

public long getLastFileModification()
Returns the most recent modification date of the involved files.


getLastModified

public long getLastModified()
Returns the last modification time.


setLastModified

public void setLastModified(long lastModified)
Sets the last modification time.


invalidate

public void invalidate()
Invalidates the item.


isInvalidated

public boolean isInvalidated()

setTimeToLive

public void setTimeToLive(long ttl)

isExpired

public boolean isExpired()

exists

public boolean exists()
Checks whether the cache file exists, is a regular file and any data has been ever written into it.


getSize

public int getSize()
Returns the size of the cached data in bytes.


getDir

protected File getDir()

setContentType

public void setContentType(String contentType)
Sets the Content-Type.


setSetContentLength

public void setSetContentLength(boolean setContentLength)
Sets whether a Content-Length header should be set.


setHeaders

public void setHeaders(Headers headers)
Sets HTTP headers.


getHeaders

public Headers getHeaders()

setCookies

public void setCookies(Cookies cookies)
Sets cookies.


setProperties

public void setProperties(Map<String,String> properties)
Sets shared properties.

See Also:
SharedProperties

getProperties

public Map<String,String> getProperties()
Returns the properties.


getWriter

public Writer getWriter()
                 throws UnsupportedEncodingException,
                        FileNotFoundException
Throws:
UnsupportedEncodingException
FileNotFoundException

getOutputStream

public OutputStream getOutputStream()
                             throws FileNotFoundException
Throws:
FileNotFoundException

gzipContent

public void gzipContent()
                 throws IOException
Throws:
IOException

writeTo

public void writeTo(HttpServletResponse response)
             throws IOException
Throws:
IOException

writeTo

public void writeTo(OutputStream out)
             throws IOException
Throws:
IOException

writeTo

public void writeTo(Writer out)
             throws IOException
Throws:
IOException

clear

public void clear()
           throws IOException
Throws:
IOException

delete

protected void delete()

toString

public String toString()
Overrides:
toString in class Object