[concurrency-interest] Implementation of a global configuration cache

Thejo Kote thejo at kote.in
Mon Jun 15 05:21:31 EDT 2009


Hi Peter,

Off the shelf caches like ehcache and JCS are definitely an option I want to
look into. Since I want to cache only around 10 items, two of which keep
changing, I wanted to know if there is a way to achieve it without using a
full fledged off the shelf cache. I also hope to learn more about the common
design approaches and concurrency issues involved in implementing such a
cache. If the effort is too much, I will use something that is already
available and not succumb to NIH :)

Thejo

On Mon, Jun 15, 2009 at 2:38 PM, Peter Veentjer <alarmnummer at gmail.com>wrote:

> Hi Thejo,
>
> would a COTS (common of the shelf) cache not be easier to use? It
> saves you a lot of time compared to writing one yourself.
>
> e.g.
>
> ehcache.
>
> On Mon, Jun 15, 2009 at 10:56 AM, Thejo Kote<thejo at kote.in> wrote:
> > Hi,
> >
> > I'm trying to improve the design of a global configuration cache which
> > currently consists of public static variables in a class. Something like
> -
> >
> > public final class ConfigCache {
> >
> >     public static String val1;
> >     public static Map<Integer, MyObj> val2;
> >
> >     public static initializeCache() {
> >         val1 = ....;
> >     }
> >
> > }
> >
> > I use the config values in other parts of the applications as
> > ConfigCache.val1 etc. The task performed by the application is highly
> > parallelizable and many threads read the configuration values. Some
> config
> > values don't change after initialization at start up and some (like val2)
> > are periodically (every 15 minutes) read from a database and updated in
> the
> > cache from a separate thread. I take advantage of the fact that writes to
> > and reads of references are always atomic when updating cache values in
> run
> > time.
> >
> > With that background -
> >
> > - Are the visibility characteristics of static and non-static variables
> the
> > same? Is it just sheer luck that the reading threads pick up the last
> > updated reference, and should they be declared as volatile?
> > - I'm ensuring that no references escape by initializing the cache before
> > the application accepts requests, but using public static fields is not
> > ideal and does not provide the required encapsulation. Is there a
> standard
> > pattern for implementing such a configuration cache where many threads
> > constantly read values with an occasional write. Is a singleton object
> with
> > proper use of read write locks on the values that keep changing the right
> > solution?
> >
> > Thanks,
> > Thejo
> >
> >
> > _______________________________________________
> > Concurrency-interest mailing list
> > Concurrency-interest at cs.oswego.edu
> > http://cs.oswego.edu/mailman/listinfo/concurrency-interest
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20090615/434bb3d0/attachment.html>


More information about the Concurrency-interest mailing list