Package lazyj

Class CachingStructure

java.lang.Object
lazyj.CachingStructure
All Implemented Interfaces:
Comparable<CachingStructure>

public final class CachingStructure extends Object implements Comparable<CachingStructure>
Holding class for page cache entries
Since:
2006-10-04
Author:
costing
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    Number of accesses to this cache entry.
    final long
    The time when this cache entry was generated
    final long
    Lifetime, in milliseconds, from the moment of its registration in the PageCache.
    final String
    Content type (defaults to text/html)
    final String
    Unique key to access this content
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    For sorting first by the number of accesses then by the key, then by expiration time
    boolean
    Whether or not two objects are in fact the same structure
    byte[]
    Get the contents.
     
    int
    Get the memory footprint of the cached content.
    int
    Rewrite the default hash distribution method
    int
    Get the size of the cached content.
    void
    setHeaders(javax.servlet.http.HttpServletResponse response)
    Set the proper HTTP headers for this cached content
    Overriden toString() produces a nicer HTML output, for web statistics

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • lGenerated

      public final long lGenerated
      The time when this cache entry was generated
    • lifetime

      public final long lifetime
      Lifetime, in milliseconds, from the moment of its registration in the PageCache.
    • sKey

      public final String sKey
      Unique key to access this content
    • iAccesses

      public int iAccesses
      Number of accesses to this cache entry.
    • sContentType

      public final String sContentType
      Content type (defaults to text/html)
  • Method Details

    • getContent

      public byte[] getContent()
      Get the contents.
      Returns:
      the contents of the cache
    • setHeaders

      public void setHeaders(javax.servlet.http.HttpServletResponse response)
      Set the proper HTTP headers for this cached content
      Parameters:
      response - object to set the headers on
    • getContentAsString

      public String getContentAsString()
      Returns:
      the String representation of this cache entry. Useful for JSPs where we anyway have to convert to String. This method caches the returned value so it's more efficient to use it instead of new String(getContent()) each time
    • compareTo

      public int compareTo(CachingStructure cs)
      For sorting first by the number of accesses then by the key, then by expiration time
      Specified by:
      compareTo in interface Comparable<CachingStructure>
      Parameters:
      cs - object to compare to
      Returns:
      sort order
    • equals

      public boolean equals(Object o)
      Whether or not two objects are in fact the same structure
      Overrides:
      equals in class Object
      Parameters:
      o - object to compare to
      Returns:
      true if the two objects are the same, false otherwise
    • hashCode

      public int hashCode()
      Rewrite the default hash distribution method
      Overrides:
      hashCode in class Object
      Returns:
      hash code of the key combined with the number of accesses
    • length

      public int length()
      Get the size of the cached content. Beware that the actual content might be compressed in memory to save space.
      Returns:
      size of the cached data entry
    • getRealSize

      public int getRealSize()
      Get the memory footprint of the cached content. Might be less than the original size if a compression was applied.
      Returns:
      original content size
    • toString

      public String toString()
      Overriden toString() produces a nicer HTML output, for web statistics
      Overrides:
      toString in class Object