[concurrency-interest] How to implement a self populating memoizer cache?

√iktor Klang viktor.klang at gmail.com
Wed Nov 3 08:26:03 EDT 2010


How do you do cache evictions/invalidations on top of that? Storing
SoftRefs?

On Wed, Nov 3, 2010 at 12:48 PM, Christian Vest Hansen <karmazilla at gmail.com
> wrote:

> Here's a simple algorithm based on ConcurrentHashMap:
>
> Try .get'ing the value by the key.
>  * If the value is a CountDownLatch, then wait on the latch, then get
> again and return that value.
>  * If the value is otherwise something non-null, then return it.
>  * If the value is null, then create a new CountDownLatch with count
> 1, and putIfAbsent on the key.
>  ** If the value returned by putIfAbsent is null, then create our real
> value, put it, and count the latch down.
>  ** If the value is a latch, wait on it and return the result of getting
> again.
>  ** Otherwise return whatever you got.
>
> Note that this algorithm does not support nulls as values, so you'd
> have to use a Null Object if you need to support nulls.
>
> On Wed, Nov 3, 2010 at 10:07, Nader Aeinehchi <nader at aeinehchi.com> wrote:
> > Hello
> >
> > How can a self populating cache be implemented?
> >
> > Requirements:
> >
> > 1. the put(key,value) operation will be a memoizer (value =
> > computer(computable)) where computable==key.
> > 2. how can a remove operation be implemented?
> > 3. the cache will be thread safe
> > 4. the cache will have a good performance for up to upper medium
> contention
> > (i.e. very high contention is not required)
> > 5. preferrably a non-blocking algorithm
> > 6. no need for timers,....
> >
> > In advance, thank you very much.
> >
> > _______________________________________________
> > Concurrency-interest mailing list
> > Concurrency-interest at cs.oswego.edu
> > http://cs.oswego.edu/mailman/listinfo/concurrency-interest
> >
>
>
>
> --
> Venlig hilsen / Kind regards,
> Christian Vest Hansen.
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>



-- 
Viktor Klang,
Code Connoisseur
Work:   akka.io
Code:   github.com/viktorklang
Follow: twitter.com/viktorklang
Read:   klangism.tumblr.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20101103/6638d1e3/attachment.html>


More information about the Concurrency-interest mailing list