jakarta-jcs-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Amitay Dobo <amit...@gmail.com>
Subject Updating a cache item without affecting it's removal from cache by LRU
Date Mon, 28 Dec 2009 10:40:29 GMT
We use a system which caches resources, but asynchronously updates the cache
contents for each resource on various intervals (so when getting from the
cache you will always have up to date content). Resources in the cache that
are not used should be removed by the cache mechanism, and stopped being

The problem is, from what we witness, is that both checking if an item is
still in the cache, and by updating its data, JCS  mark it as accessed, and
the LRU Memory prevents it from being purged from the cache.
This can be demonstrated by this test code:

        JCS cache = null;

        try {
            cache = JCS.getInstance("default");
        } catch (CacheException e) {

        // Put the first item
        cache.put("key", "data");

        for (Integer i = 0; i < 1005; i++) {
            // Put and access some other keys in the cache. Since they are
accessed they should be kept
            cache.put("key" + i.toString(), "data");
            cache.get("key" + i.toString());

            // Update the data for the first key. Removing this lines causes
the test to pass with no exception.
            cache.put("key", "dataNew");


        // get the first inserted key, after more items than MaxObjects were
put and accessed.
        String valueAfterWait = (String) cache.get("key");


        if (!(valueAfterWait == null)) {
            throw new RuntimeException("Data should be null. actual value is
" + valueAfterWait);


In the actual code we *DO* need to access the cache for the original key
somehow, to see if there still is a cache for it, other wise we don't want
to re-insert it.
I saw on a similiar discussion (
http://www.mail-archive.com/jcs-users@jakarta.apache.org/msg00783.html) that
there is a getQuiet() method in org.apache.jcs.engine.memory.AbstractMemory
, but It doesn't seem like a good idea to use it, and i want the disk
caching to work well.

To sum it:
* Is there a way to peek at a cache item (or just check if it exists) and
update its data without the item being considered as accessed?

Amitay Dobo

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message