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
updated.

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) {
            e.printStackTrace();
        }

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

        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");

        System.out.println(cache.getStats());

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

Cache.ccf:
# DEFAULT CACHE REGION
jcs.default=
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=1000
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache

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?

Thanks,
Amitay Dobo

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