atomic writes to ehcache

Posted by Jacques René Mesrine on Stack Overflow See other posts from Stack Overflow or by Jacques René Mesrine
Published on 2010-04-01T10:26:52Z Indexed on 2010/04/01 10:43 UTC
Read the original article Hit count: 527

Context

I am storing a java.util.List inside ehcache.

Key(String) --> List<UserDetail>

The ordered List contains a Top 10 ranking of my most active users.

Problem

Concurrent 3rd party clients might be requesting for this list. I have a requirement to be as current as possible with regards to the ranking. Thus if the ranking is changed due the activities of users, the ordered List in the cache must not be left stale for very long. Once I've recalculated a new List, I want to replace the one in cache immediately.

Consider a busy scenario whereby multiple concurrent clients are requesting for the ranking; how can I replace the cache item in an fashion such that: Clients can continue to pull a possibly stale snapshot. They should never get a null value.

There will only be 1 server thread that writes to the cache.

© Stack Overflow or respective owner

Related posts about ehcache

Related posts about caching