
|
If you were logged in you would be able to see more operations.
|
|
|
OSCache
Created: 08/Nov/06 04:02 AM
Updated: 19/Mar/07 05:53 PM
|
|
| Component/s: |
None
|
| Affects Version/s: |
2.3.2
|
| Fix Version/s: |
2.4
|
|
|
1. Brief description
The ServletCacheAdministrator should dynamically build its CacheAdministratorKey using the CacheKey from the supplied Properties if any, or the default CacheKey if none is available. This then provides the flexibility to have multiple ServletCacheAdministrators managing multiple Caches each with different Properties. Static method calls that fail to specify the CacheKey, CacheAdministratorKey and/or Properties, will inevitably access the default ServletCacheAdministrator and its properties.
2. Rationale for the change
You can have multiple GeneralCacheAdministrators each managing a different underlying Cache with its own Properties file. You can also specify the Properties to be used when constructing a ServletCacheAdministrator, but because the ServletCacheAdministrator stores itself in the ServletContext using a fixed key, you cannot have more than one. But the fact you can specify the Properties file when constructing the ServletCacheAdministrator is a perhaps little misleading since it suggests it may be possible to have multiple ServletCacheAdministrators with different Properties.
Once it is possible to have multiple ServletCacheAdministrators, it becomes possible for the CacheFilter to have an additional Deployment descriptor initialization parameter: oscache-properties-file, which when set causes the CacheFilter to obtain a ServletCacheAdministrator with the settings in that file. A web application is then able to have multiple CacheFilters each with a different configuration tailored to the requirements of the application. Example: one instance is caching the responses from a dynamic image servlet and is set to not use memory, another instance is set to use the default properties for caching HTML responses and the default properties file specifies a large memory cache.
3. How to achieve this
(I assume here that the key used to put the ServletCacheAdministrator into the ServletContext must be different from the CacheKey. If this is not the case, the following could obviously be simpler)
* Rename the static variable ServletCacheAdministrator.CACHE_ADMINISTRATOR_KEY to ServletCacheAdministrator.CACHE_ADMINISTRATOR_KEY_SUFFIX
* Create new static variable ServletCacheAdministrator.CACHE_ADMINISTRATORS_KEY (see below)
* modify ServletCacheAdministrator.getInstance method so that the ServletCacheAdministratorKey used to store the ServletCacheAdministrator in the ServletContext is equal to Properties.getCacheKey + CACHE_ADMINISTRATOR_KEY_SUFFIX
* ServletCacheAdministrator.destroyInstance() needs to be able to retrieve all CacheAdministratorKeys from somewhere and then iterate over them to destroy each instance. To achieve this, store an array of keys in the servlet context. The key for the array is a new static variable in the ServletCacheAdministrator class, and the ServletCacheAdministrator.getInstance method needs to retrieve this array from the ServletContext if available, append to it and save it back.
* add a new convenience static method that allows for the retrieval of a ServletCacheAdministrator by specifying the ServletContext and CacheKey (String)
Lastly, modify the CacheFilter.init to check for an initialization parameter "properties-file" or similar, and if there is a properties file, construct the ServletCacheAdministrator with this properties file (after first loading it into a Properties object obviously).
4. Subsequent enhancements
* update documentation in particular the comments in the oscache.properties file
* Tags in the tag library need improving to allow the cache to be specified, probably using the cache key. If no cache key is specified, the default cache key (and consequently default ServletCacheAdministrator) is used
|
|
Description
|
1. Brief description
The ServletCacheAdministrator should dynamically build its CacheAdministratorKey using the CacheKey from the supplied Properties if any, or the default CacheKey if none is available. This then provides the flexibility to have multiple ServletCacheAdministrators managing multiple Caches each with different Properties. Static method calls that fail to specify the CacheKey, CacheAdministratorKey and/or Properties, will inevitably access the default ServletCacheAdministrator and its properties.
2. Rationale for the change
You can have multiple GeneralCacheAdministrators each managing a different underlying Cache with its own Properties file. You can also specify the Properties to be used when constructing a ServletCacheAdministrator, but because the ServletCacheAdministrator stores itself in the ServletContext using a fixed key, you cannot have more than one. But the fact you can specify the Properties file when constructing the ServletCacheAdministrator is a perhaps little misleading since it suggests it may be possible to have multiple ServletCacheAdministrators with different Properties.
Once it is possible to have multiple ServletCacheAdministrators, it becomes possible for the CacheFilter to have an additional Deployment descriptor initialization parameter: oscache-properties-file, which when set causes the CacheFilter to obtain a ServletCacheAdministrator with the settings in that file. A web application is then able to have multiple CacheFilters each with a different configuration tailored to the requirements of the application. Example: one instance is caching the responses from a dynamic image servlet and is set to not use memory, another instance is set to use the default properties for caching HTML responses and the default properties file specifies a large memory cache.
3. How to achieve this
(I assume here that the key used to put the ServletCacheAdministrator into the ServletContext must be different from the CacheKey. If this is not the case, the following could obviously be simpler)
* Rename the static variable ServletCacheAdministrator.CACHE_ADMINISTRATOR_KEY to ServletCacheAdministrator.CACHE_ADMINISTRATOR_KEY_SUFFIX
* Create new static variable ServletCacheAdministrator.CACHE_ADMINISTRATORS_KEY (see below)
* modify ServletCacheAdministrator.getInstance method so that the ServletCacheAdministratorKey used to store the ServletCacheAdministrator in the ServletContext is equal to Properties.getCacheKey + CACHE_ADMINISTRATOR_KEY_SUFFIX
* ServletCacheAdministrator.destroyInstance() needs to be able to retrieve all CacheAdministratorKeys from somewhere and then iterate over them to destroy each instance. To achieve this, store an array of keys in the servlet context. The key for the array is a new static variable in the ServletCacheAdministrator class, and the ServletCacheAdministrator.getInstance method needs to retrieve this array from the ServletContext if available, append to it and save it back.
* add a new convenience static method that allows for the retrieval of a ServletCacheAdministrator by specifying the ServletContext and CacheKey (String)
Lastly, modify the CacheFilter.init to check for an initialization parameter "properties-file" or similar, and if there is a properties file, construct the ServletCacheAdministrator with this properties file (after first loading it into a Properties object obviously).
4. Subsequent enhancements
* update documentation in particular the comments in the oscache.properties file
* Tags in the tag library need improving to allow the cache to be specified, probably using the cache key. If no cache key is specified, the default cache key (and consequently default ServletCacheAdministrator) is used
|
Show » |
|
ServletCacheAdministrator.java (based on revision 391)
CacheFilter.java (based on revision 362)
I have deviated slightly from what I originally described in the course of implementation, but the gist and end result is the same.