de.neteye.actioncache
Class AbstractCacheableAction

java.lang.Object
  |
  +--org.apache.struts.action.Action
        |
        +--de.neteye.actioncache.AbstractCacheableAction
All Implemented Interfaces:
CacheableAction
Direct Known Subclasses:
ExampleAction

public abstract class AbstractCacheableAction
extends org.apache.struts.action.Action
implements CacheableAction

Abstract class that implements time based expiration. Subclasses can overide the getTimeToLive() method to return the number of milliseconds that must elapse before getLastModified is called again.

Version:
$Revision: 1.3 $
Author:
Felix Gnass

Field Summary
protected static int DEFAULT_TTL
           
 
Fields inherited from class org.apache.struts.action.Action
ACTION_SERVLET_KEY, APPLICATION_KEY, DATA_SOURCE_KEY, defaultLocale, ERROR_KEY, EXCEPTION_KEY, FORM_BEANS_KEY, FORWARDS_KEY, LOCALE_KEY, MAPPING_KEY, MAPPINGS_KEY, MESSAGE_KEY, MESSAGES_KEY, MULTIPART_KEY, PLUG_INS_KEY, REQUEST_PROCESSOR_KEY, servlet, SERVLET_KEY, TRANSACTION_TOKEN_KEY
 
Constructor Summary
AbstractCacheableAction()
           
 
Method Summary
abstract  org.apache.struts.action.ActionForward execute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 java.lang.String getCacheKey(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Returns the action's class name by default.
 long getLastModified(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          The default implementation returns System.currentTimeMillis() so that the item is refreshed as soon as it expires.
 long getLastModified(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ActionCacheItem cacheItem)
          First checks if given CacheItem is older than the time to live.
 int getTimeToLive(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Returns 5000 as default.
 
Methods inherited from class org.apache.struts.action.Action
execute, generateToken, getDataSource, getDataSource, getLocale, getResources, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, perform, perform, resetToken, saveErrors, saveMessages, saveToken, setLocale, setServlet, toHex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TTL

protected static final int DEFAULT_TTL
See Also:
Constant Field Values
Constructor Detail

AbstractCacheableAction

public AbstractCacheableAction()
Method Detail

getCacheKey

public java.lang.String getCacheKey(org.apache.struts.action.ActionMapping mapping,
                                    org.apache.struts.action.ActionForm form,
                                    javax.servlet.http.HttpServletRequest request,
                                    javax.servlet.http.HttpServletResponse response)
Returns the action's class name by default. Subclasses that react on parameters must include these in the returned key.

Specified by:
getCacheKey in interface CacheableAction

getLastModified

public final long getLastModified(org.apache.struts.action.ActionMapping mapping,
                                  org.apache.struts.action.ActionForm form,
                                  javax.servlet.http.HttpServletRequest request,
                                  javax.servlet.http.HttpServletResponse response,
                                  ActionCacheItem cacheItem)
                           throws java.io.IOException,
                                  javax.servlet.ServletException
First checks if given CacheItem is older than the time to live. If it has expired, the abstract getLastModified() method is called. In case the actual modification time is not newer than cached item, the item is "touched" and will live for another timeToLive milliseconds.

Specified by:
getLastModified in interface CacheableAction
java.io.IOException
javax.servlet.ServletException

getLastModified

public long getLastModified(org.apache.struts.action.ActionMapping mapping,
                            org.apache.struts.action.ActionForm form,
                            javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response)
                     throws java.io.IOException,
                            javax.servlet.ServletException
The default implementation returns System.currentTimeMillis() so that the item is refreshed as soon as it expires. Subclasses should override this method to return something reasonable.

java.io.IOException
javax.servlet.ServletException

getTimeToLive

public int getTimeToLive(org.apache.struts.action.ActionMapping mapping,
                         org.apache.struts.action.ActionForm form,
                         javax.servlet.http.HttpServletRequest request,
                         javax.servlet.http.HttpServletResponse response)
Returns 5000 as default.


execute

public abstract org.apache.struts.action.ActionForward execute(org.apache.struts.action.ActionMapping mapping,
                                                               org.apache.struts.action.ActionForm form,
                                                               javax.servlet.http.HttpServletRequest request,
                                                               javax.servlet.http.HttpServletResponse response)
                                                        throws java.io.IOException,
                                                               javax.servlet.ServletException
Overrides:
execute in class org.apache.struts.action.Action
java.io.IOException
javax.servlet.ServletException