3 Replies Latest reply on Oct 16, 2009 7:29 AM by Manik Surtani

    Override FileCacheStore

    Robert Bowen Newbie

      Would it be possible to change the way FileCacheStore is storing things on the disk?

      Currently if you do a put of (1,"hello") Infinispan creates a file called "1" and stores "hello" inside of it.

      Our data is a bit more complex. We'd like to be able to create a "1" directory and within that directory have various files:

      1/hello
      1/hello2
      1/hello3

      Would it be possible to override FileCacheStore so it stores stuff like this? I've been looking at BucketBasedCacheStore, the class it extends, and it doesn't look trivial.

      Thanks,
      Bob

        • 1. Re: Override FileCacheStore
          Manik Surtani Master

          The BucketBasedCacheStore actually stores stuff in a bucket, named on the hashcode of the key. So multiple entries whose keys share the same hashcode will be in the same bucket. The FileCacheStore extends the BucketBasedCacheStore to write this bucket to a file, so you would have files named "1", as that would be the hashcode of the key "1".

          If you wanted to change this, you would have to implement CacheStore directly, or perhaps extend AbstractCacheStore. Not BucketBasedCacheStore.

          • 2. Re: Override FileCacheStore
            Robert Bowen Newbie

            Hmmm. But of course if I do the following:

            cache.put(1, "hello");
            cache.put(1, "world");

            I have exactly one file with the name "1" in my store, whose contents are "world" because the second put over-writes the first. That's how the cache works, so I'm not sure how to tell the Bucket to do otherwise.

            But it doesn't matter really because we are realizing that our definition of a store isn't Infinispan's. Infinispan uses the store to a) save items that don't fit in the cache, once the cache becomes bigger than the max size allowed, and b) to load data off the disk (or database) at startup.

            We, on the other hand, want to create a memory cache that contains a String id and a small POJO value. Within this POJO is the path on the disk (an NFS mount, shared between cluster members) where this item's corresponding XML file is stored. We then load the XML file. We can't store the XML files themselves in the cache, there are hundreds of thousands of them, even millions, and they can way up to 10 Mb or more. So we store them on disk.

            So it seems we don't really want to use Infinispan's built-it store. Rather we'd like to be able to somehow be able to use a listener or an interceptor of some kind, so that after each get/put we can automatically go to the disk and load/save the XML.

            Is this possible? I've been looking at Interceptore, Visitors and VisitableCommands but I'm not really sure how to go about it.

            Any help much appreciated!
            Bob