Re: CacheableAction always regenerated
Status: Inactive
Brought to you by:
fgnass
|
From: Felix G. <fel...@ne...> - 2004-02-07 12:48:29
|
Hi Martin,
first of all you shouldn't use private fields in Actions since they are
shared by multiple threads! But back to your problem:
the lastModified time of an ActionCacheItem is automatically set to
System.currentTimeMillis() as soon as ActionCacheItem.setValue() is
called (i.e. some data is cached). This also happens for newly
constructed CacheItems.
If the log level is set to debug you should see "Stale cache item" in
your log file, followed by "Caching response..." (which - what a shame -
is a System.out.println() and might be written to another logfile,
depending on your logging configuration).
However, if no exception occurs, the data should be then written to disk
and the lastModified field of the cacheItem should be set. If you don't
see the message "Stale cache item", you should empty your cache directory!
~felix
Martin Alley wrote:
>Hi Felix,
>
>Thanks for the quick response!
>
>Initially my implementation of getLastModified was simply
> return 0;
>
>but then I changed it so I have a private lastModified var in my
>CacheableAction, which I set in my doExecute method - I simply set it to
>the current time (System.currentTimeMillis()).
>
>My getLastModified method now looks like this:
> public long getLastModified(ActionMapping arg0, ActionForm arg1,
>HttpServletRequest arg2, HttpServletResponse arg3, ActionCacheItem arg4)
>throws IOException, ServletException {
> _log.debug("getLastModified");
> arg4.setLastModified(lastModified);
> return lastModified;
> }
>
>but the function is not called!
>
>This makes sense to me as
>ActionCacheRequestProcessor.processActionPerform only calls
>cacheItem.getLastModified() if !cacheItem.isNew(), which won't happen.
>
>Can you give me further guidance?
>
>Thanks alot
>Martin
>
>-----Original Message-----
>From: Felix Gnass [mailto:fel...@ne...]
>Sent: 07 February 2004 11:11
>To: Martin Alley
>Cc: act...@li...
>Subject: Re: CacheableAction always regenerated
>
>Hi Martin,
>
>if you don't subclass AbstractCacheableAction, you have to call
>cacheItem.setLastModified() in your getLastModified method. Just have a
>look at AbstractCacheableAction to how its done there.
>
>This way it's possible to implement time-based caching, that prevents
>the execution of an expensive getLastModified() method (database calls
>etc.) for a certain amount of time. I think we should change the way
>isNew() works, to allow a straight forward implementation of
>getLastModified(). Thanks for your feedback Martin!
>
>~felix
>
>Martin Alley wrote:
>
>
>
>>Hi,
>>
>>I am using actioncache v 1.1.1
>>
>>I want to take the shortest route to getting cached output in my struts
>>based project, so I have make my Action implement CacheableAction.
>>
>>The code still runs, and serves the page okay, but the content is still
>>be generated each time, not served from the cache.
>>
>>I have looked at ActionCacheRequestProcessor.processActionPerform, and
>>this is what I see:
>>The items are being put in the cache, and found next time they are
>>needed (AbstractCache.getItem is calling touch(item)), but back in
>>ActionCacheRequestProcessor.processActionPerform, cacheItem.isNew() is
>>true, because lastModified is NOT_YET.
>>
>>I cannot see where ActionCacheItem.setLastModified is called.
>>
>>Can anyone help?
>>Thanks
>>Martin
>>
>>
>>
>>
>
>
>
>
|