2 Replies Latest reply on Apr 14, 2008 10:12 PM by smitchelus

    Help configuring invalidation to work for me

    smitchelus

      Hi, I am trying to get JBoss Cache to work in a very specific way that I have used with another caching product in the past, but I've run into a road block that I just can't seem to get past.

      The setup I'd like to have is one where I have several JVM's (A, B, and C let's say) in contact with each other. Each essentially has his own independent cache, but when one of the items in the cache gets updated in the database we would send an eviction notice to all members of the cluster so that they would purge that item out of their local cache and re-read it from the database the next time it is requested.

      I initially thought that the invalidation_async mode was what I needed. However, it turns out that an evict notification goes out to the other nodes as soon as one node puts the item into their cache. So what was happening to us was:
      * JVM A puts an item in it's cache
      * evict notification goes out to B and C
      * when the item is requested on JVM B it looks up the data from the db and adds it to it's local cache.
      * evict notification goes out to A and C
      * item requested on JVM A again but it has been invalidated so it looks it up from the db and puts it in the cache.
      * evict notice goes out to B and C again

      So the cache just keeps getting invalidated again and again and the actual row in the database has never been updated!

      Is there anyway to configure this basic setup in a way such that putting an item into the cache doesn't send the eviction notification?

      Thanks,
      Scott

        • 1. Re: Help configuring invalidation to work for me
          brian.stansberry

          Use the Cache.putForExternalRead() method when you are caching something that was just read from an external authoritative source (aka an RDBMS). If the cache is configured for invalidation, that method will not generate an invalidation msg. Then use put() if you are creating something new or have updated something. That *will* generate an invalidation msg, as it should.

          The above is a quick description of how the latest Hibernate 2nd Level Cache impl uses JBC; the putForExternalRead() method was added and tweaked and massaged exactly for your use case. ;)

          • 2. Re: Help configuring invalidation to work for me
            smitchelus

            Thanks Brian, I've upgraded my local env to v2 and have started to play with using that call. It looks promising so far!