4 Replies Latest reply on Aug 6, 2007 2:10 PM by adamw

    "Renewable" cache

    adamw

      Hello,

      in JBoss Labs, we are using a cache-like component, which holds some data based on what is present in a persistent store (SVN in our case). The key thing is that the data is:
      1. always in the cache
      2. renewed when the persistent store changes (so, when a change occurs, a new object based on the persistent data is created in the background and only when ready, replaces the old one).

      This way, users always have the data fast (as it always read from the cache), maybe with the exception of first access to a key.

      I was wondering if this is possible to achieve using CacheLoaders/EvictionPolicies, but I have doubts if it is possible? One problem is that in this case nodes should become evicted because of persistent store changes, not because operation on nodes have been done recently/frequently/etc. So it may be possible that the eviction mechanism isn't the proper one to use here.

      The other problem is "renewing" a key in the cache: logically, it should be done using a cache loader. However here, it turns out this would be done when evicting a node (or the eviction policy can call the cache loader using CacheSPI ....)

      Anyway, if you have any opinions on if it is possible to integrate the "my" cache with jboss cache, or any suggestions, please write :)

      --
      Adam

        • 1. Re:
          manik

          You could write an SVN-based cache loader - basically a loader that uses SVN to read contents, generate the cache objects.

          You would probably configure this not to use an eviction policy though, since you don't want objects to expire, rather to trigger an eviction when SVN detects a change. So you would have to write your own code to listen for changes in SVN, and when a key has changed, manually evict the key (or all affected keys) from the cache using the cache.evict() API.

          Once the keys are evicted, the next call that comes in for this key will trigger a load from the CacheLoader, which could then build the object on demand.

          • 2. Re:
            adamw

            Hello,

            I have the code written though it's completely separate from jboss cache. As it doesn't make much sense to write a separate cache, I want to intergrate it.

            However I think I cannot use CacheLoaders too, because I don't want any calls to trigger loads from the CacheLoader --- the keys have to be updated in the background. So basically, a thread watches for changes in the backing store (SVN, filesystem, etc), and when a change is detected, updates the current value with a new one. The user never has to wait for the value to be read from the store, parsed and so on.

            (The thread-approach is more or less how it is now, I was just wondering if it could be done with cache loaders/ eviction policies, but I suppose not)

            --
            Adam

            • 3. Re:
              manik

              Then I suppose just use the cache as a cache, don't use eviction policies or cache loaders. :-)

              • 4. Re:
                adamw

                That's what I'll do. Thanks for the answers :)

                --
                Adam