Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 318646 - TocServlet responseByLocale cache cannot be cleared programatically
Summary: TocServlet responseByLocale cache cannot be cleared programatically
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: User Assistance (show other bugs)
Version: 4.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7 M5   Edit
Assignee: Chris Austin CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 280457 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-07-01 15:50 EDT by Jim Perry CLA
Modified: 2011-01-21 14:55 EST (History)
2 users (show)

See Also:


Attachments
Patch for adding method to set the toc cache invalid which forces a refresh (1.40 KB, patch)
2010-09-29 23:20 EDT, Jim Perry CLA
no flags Details | Diff
Patch - Public API Version (3.80 KB, patch)
2011-01-18 13:17 EST, Chris Austin CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jim Perry CLA 2010-07-01 15:50:09 EDT
Build Identifier: eclipse-SDK-3.6RC4-win32

The TocServlet has a shared instance 

Map responseByLocale

which tracks the toc xml returns for each locale that is requested.  If the toc was built for a certain locale, and then changes to the help system are made elsewhere, there is no way to clear the responseByLocale cache to force a rebuild of the help system.  It would be helpful to be able to programatically clear the TocServlet response cache if needed.

Reproducible: Always

Steps to Reproduce:
1. Call the TocServlet for a particular locale
3. Try to call TocServlet for same locale and have it rebuild
Comment 1 Jim Perry CLA 2010-09-29 23:20:15 EDT
Created attachment 179914 [details]
Patch for adding method to set the toc cache invalid which forces a refresh

This path provides the method:

public static void setCacheInvalid()
	{
		cacheInvalid=true;
	}

So the toc cache can be forced to refresh if changes to the toc have been made.

The variable is added to the check for determine if a new HashMap is needed.

if (responseByLocale == null || cacheInvalid) {
			responseByLocale = new WeakHashMap();
		}
Comment 2 Chris Goldthorpe CLA 2010-09-30 13:29:54 EDT
Are you looking to create API so that an application which extends Eclipse can clear this cache? If so you would need to add the method to an API class - TocServlet is internal. The other problem with the patch is that once cacheInvalid is false it never gets reset to being true.
Comment 3 Jim Perry CLA 2010-09-30 14:40:22 EDT
Hi Chris,

Thanks for the response.  I agree an API class would be better.  Is there an an API class I can use as an example?  Is there an existing API class that this method would make sense to go in?

Also, the cacheInvalid does need to be set to true as you said.
Comment 4 Chris Austin CLA 2010-12-10 15:05:34 EST
So I think the public API might look someything like this:

org.eclipse.help.webapp: org.eclipse.help.webapp.TocSystem

TocSystem has a method, clearTocCache which calls the TocServlet.setCacheInvalid() method.
Comment 5 Chris Austin CLA 2010-12-10 15:08:11 EST
*** Bug 280457 has been marked as a duplicate of this bug. ***
Comment 6 Chris Austin CLA 2011-01-18 13:17:58 EST
Created attachment 187031 [details]
Patch - Public API Version
Comment 7 Chris Goldthorpe CLA 2011-01-20 16:36:07 EST
I took a quick look at the patch and the API looks good. One thing we should think about is making this code thread safe - the current code is not perfect in that respect. 

I'm still trying to understand the initial requirement. Currently the help system works on the assumption that the table of contents does not change after it is first built and the TocServlet is just one instance of that assumption.
Comment 8 Chris Austin CLA 2011-01-21 09:57:22 EST
(In reply to comment #7)
> I took a quick look at the patch and the API looks good. One thing we should
> think about is making this code thread safe - the current code is not perfect
> in that respect. 

Yeah - I was thinking the same, but I did not have time to come up with a solution for it.

> I'm still trying to understand the initial requirement. Currently the help
> system works on the assumption that the table of contents does not change after
> it is first built and the TocServlet is just one instance of that assumption.

The requirement is for doc installs.  We need a way to update the Table of Contents after new doc has been installed, without restarting the help system.  Internally, we have been using a clear cache patch on the org.eclipse.help.webapp plugin and it has been very helpful in refreshing the toc after new content has been installed.
Comment 9 Chris Austin CLA 2011-01-21 14:55:35 EST
Patch committed to HEAD