History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: CACHE-144
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Lars Torunski
Reporter: Andreas Rasmusson
Votes: 1
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
OSCache

CacheTag doesn't clear variables in doStartTag / doFinally

Created: 23/Feb/05 06:31 AM   Updated: 06/Nov/05 11:19 AM
Component/s: Tags
Affects Version/s: 2.1
Fix Version/s: 2.2 RC


 Description  « Hide
(Pardon if i misuse some jsp/servlet jargon slightly.. I'm not an expert)

When caching a page and using the <cache:addGroup> -tag i noticed that the HashSet that contains the cache-keys depending on this group contained many more entries than they should.

Apparently instances of the cache-tag objects are resused by the web-container (In my case Tomcat). This is "correct" behaviour for so called "classic tags". Whenever an instance is reused, first a call to doStartTag() is done, and here any instance-variables you dont want reused should be cleared.
Since the groups-variable was never cleared, the list of groups that depended on a cache-key just kept growing.

Suggested fix: add the line
  groups = null;
to the beginning of CacheTag.doStartTag()
Perhaps/probably also some other instance variables should be reset here...

Workaround: add the string 'groups=""' to the <cache:cache> tag. This forces
a re-initialization of the groups-variable.

 All   Comments   Change History      Sort Order:
Lars Torunski - [23/Feb/05 02:20 PM ]
If we fix it as suggested: add the line

groups = null;

to the beginning of CacheTag.doStartTag() and the page contains

<cache:cache key="<%= product.getId() %>" time="-1" group="currencyData, categories">

doesn't the groups information are cleared, because the groups information is passed to the Tag object through setter method calls, prior to the call to doStartTag()?

Andreas Rasmusson - [24/Feb/05 03:37 AM ]
Yes, you're probably right. I had just assumed that the attrubute setters were called after the doStartTag()-method, but that does not seem to be the case.

What if we clear the groups-variable in the doEndTag()-method instead?

Lars Torunski - [24/Feb/05 02:14 PM ]
I doesn't have any knowledge about the jsp spec, but shouldn't the values resetted in doFinally() ?
And what about the values key, cron, time etc.?

Where did you find something about the "correct" behaviour for so called "classic tags"?

Andreas Rasmusson - [25/Feb/05 08:19 AM ]
Again, yes, the doFinally() method is probably even better than the
doEndTag()-method. (Although I think it's strange if there is no method
equivalent to a counstructor where one could reset the object's state _before_ the setters are called...).

And yes (again), perhaps/probably also some other instance variables
such as key, cron, time, should be reset there...

About "correct" usage, I just tried to point out that instances of the tag-objects may be reused.
Someone at work handed me the book "Pro JSP" by Simon Brown et. al. where
they said (pp 222) "... with containes that provide instance pooling, [the release()] method is only called when the container has finished using the
instance and before it gets garbage collected".

Btw, on pp 276 in that book there is a graph showing how the doStartTag, doEndTag and doFinally are called relative to each other.

Hani Suleiman - [20/Mar/05 04:23 PM ]
doFinally is the right approach, but it is part of JSP 1.2 and not 1.1. However, since we already have a doFinally, might as well add the clearing of all local state there (this isn't just about the groups field, but all the others too).

Lars Torunski - [20/Mar/05 05:10 PM ]
We should reset (null) the following states in doFinally:
- groups
- scope (PageContext.APPLICATION_SCOPE)
- cron
- key
- language
- refreshpolicyclass
- refreshpolicyparam
- time (DEFAULT_TIMEOUT)
- refresh (false)
- mode (0)

The oscache.tld references jsp version 1.2 already.

Lars Torunski - [21/Mar/05 12:00 AM ]
solved as descriped before