Package lazyj

Class CachingStructure

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

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

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

    Modifier and Type Method Description
    int compareTo​(CachingStructure cs)
    For sorting first by the number of accesses then by the key, then by expiration time
    boolean equals​(java.lang.Object o)
    Whether or not two objects are in fact the same structure
    byte[] getContent()
    Get the contents.
    java.lang.String getContentAsString()  
    int getRealSize()
    Get the memory footprint of the cached content.
    int hashCode()
    Rewrite the default hash distribution method
    int length()
    Get the size of the cached content.
    void setHeaders​(javax.servlet.http.HttpServletResponse response)
    Set the proper HTTP headers for this cached content
    java.lang.String toString()
    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 java.lang.String sKey
      Unique key to access this content
    • iAccesses

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

      public final java.lang.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 java.lang.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 java.lang.Comparable<CachingStructure>
      Parameters:
      cs - object to compare to
      Returns:
      sort order
    • equals

      public boolean equals​(java.lang.Object o)
      Whether or not two objects are in fact the same structure
      Overrides:
      equals in class java.lang.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 java.lang.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 java.lang.String toString()
      Overriden toString() produces a nicer HTML output, for web statistics
      Overrides:
      toString in class java.lang.Object