Is there a way to specify a cache instance as "read only"?
I would like to set up an environment where some processes
(where I say process, I mean different JVM) can write to
their caches and those changes are distributed to the other
caches in the group. Likewise, some processes should not be
allowed to write to their caches. These readonly processes
basically just want to listen to a live copy of the cached
data (by attaching a cache listener). I'd like to prevent
the possibility of accidentally having one of these
supposedly read-only cache processes write to the cache.
The most obvious solution seems to be for me to make a
ReadOnlyCache interface, then attach it to TreeCache (via a
thin wrapper or injecting with an aspect or
something if that is possible). Once I have the
ReadOnlyCache, I can hide away the real cache in a singleton
somewhere and just expose the ReadOnlyCache interface to the
public. Although it makes it more difficult to screw up and
write something to the cache when you don't mean to, it
doesn't seem foolproof or elegant.
I think using a separate facade, which delegates to the cache or, in case of writes, throws an exception is what I'd do too.
We have a task in the roadmap for providing an interface to the cache, rather than direct access via the class.