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

Key: CACHE-69
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Lars Torunski
Reporter: chico charlesworth
Votes: 1
Watchers: 2
Operations

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

Custom Key Generation on CacheFilter

Created: 03/Dec/03 06:17 AM   Updated: 08/Mar/07 12:29 AM
Component/s: Filters
Affects Version/s: 2.0.2
Fix Version/s: 2.2 RC

Environment: Any Java Platform
Issue Links:
Duplicate
 
This issue is duplicated by:
CACHE-171 CacheFilter easier sub-classing via k... Major Closed
Required
 
This issue is required by:
CACHE-84 Include user locale in key generation Major Closed


 Description  « Hide
At the moment using the CacheFilter the key generation is done transparently in the ServletCacheAdministrator class.

If i wanted to have my own custom key generation (e.g. add a suffix like a request attribute), i would have to implement my own custom cache filter. The problem with this is that its not future proof, because for any new versions of oscache i would have to re-check my custom cache filter and possibly re-implement. Also its not possible currently to extend ServletCacheAdministrator (because its got a private constructor), so that i could override the generateKey method.

What would be nice if the generateKey method in ServletCacheAdministrator would accept a request attribute that allowed the cache key to be overridden completely (i.e. generateKey(CacheEntryKey key, ...)) and that the cache filter had a method where this request attribute is built (see below), therefore if i wanted to change the process of creating the cache entry key, i would simply extend CacheFilter and override this method.

// Example change to cachefilter
public class CacheFilter implements Filter {

...

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
 ...
 CacheEntryKey cacheEntryKey = generateEntryKey(httpRequest);
 key = admin.generateEntryKey(cacheEntryKey , httpRequest, cacheScope);
 ...
}

public CacheEntryKey generateEntryKey(
ServletRequest request) {

}

 All   Comments   Change History      Sort Order:
Lars Torunski - [29/Jan/05 02:09 AM ]
We should substitute the line

String key = admin.generateEntryKey(null, httpRequest, cacheScope);

with

String key = generateEntryKey(httpRequest);

and add the method

/**
     * Creates the cache key for the CacheFilter.
     *
     * @param httpRequest
     * @return the cache key
     */
    public String calculateKey(HttpServletRequest httpRequest) {
        return admin.generateEntryKey(null, httpRequest, cacheScope);
    }

Lars Torunski - [30/Jan/05 06:13 AM ]
generateEntryKey should be the method's name!

Lars Torunski - [02/Feb/05 11:55 PM ]
With the CACHE-69 implementation you can create our own cache key, which depends on the user locale also.

Lars Torunski - [04/Jul/05 12:39 PM ]
Method signature changed to

public String createCacheKey(HttpServletRequest httpRequest, ServletCacheAdministrator scAdmin, Cache cache);

to allow access to the current ServletCacheAdministrator and Cache.