This example shows how to use useCacheObj to cache generic
serializable java objects.
The cached objects are stored under the same web-based namespaced automatically
maintained by Java Web Cache system.
In this example, cache objects can be stored under the name "a1"
and "a2" under
"/demo/cache/objcache/objcache.jsp?testing4=101" . The cache
object can be retrieved under the same name later.
Similarly, the cache object can be invalidated under the same name.
Developers can still enjoy all
the naming convenience and benefit of an auto cache policy, such as, using selected
parameters feature, a sensible web-based naming hierarchy.
We use an implementation of a String Array as the generic cache object targets.
The String Array implementation is serializable. The base version of the String Array
is StrArray . It provides most of string array functions as
protected methods. There are two derived versions of the String Array:
- read-only version:
RStrArray : only exposes the read/getter operations
- writeable version:
WStrArray : exposes both read & write / getter & setter operations
Since the read-only String Array is immutable, there is no need for cloning during
cache operations. So, RStrArray does not need to implement
CloneableCacheObj interface.
Therefore, Java Web Cache does not clone the cached object of read-only String Array.
On the other hand, since the writeable String Array is mutable, we suggest you to
implement CloneableCacheObj interface to provide a (deep) copy
operation for cloning to avoid unintentional object mutation and thread-safety issue.
|