5 Replies Latest reply on Oct 20, 2006 10:30 AM by warren cooper

    how to support custom CacheLoader callbacks to register addi

    warren cooper Newbie

      I have a custom cacheloader impl that is used to fetch data on cache misses. When I fetch the data, and return my Map via the CacheLoader.get(Fqn name) interface method call, I also wish to create and register additional Fqn/DataNode pairs in the cache store. Is this possible?

      ex:

      assume a node '/a/b/c' results in a cache miss for a treeCache.get(fqn) invocation.

      In this case, my custom cache loader is called, so I will send back a java.util.Map for node '/a/b/c', but what if I also want to register addition child nodes such as /a/b/c/d1, /a/b/c/d2, etc.

      What's the best way to do this given I wish to avoid making multiple calls from in the cases where I am using TcpDelegatingCacheLoader for a distributed cache.

      thanks

        • 1. Re: how to support custom CacheLoader callbacks to register
          warren cooper Newbie

          Here's what I ended up doing...

          Since CacheLoader.setCache(TreeCache treeCache) interface method sends in the controlling treeCache instance, I use it to add any additional nodes that should be added to the cache as a result of the initial cache miss. ( When I call my external service to get data, it returns additional data nodes to add to the cache.) As long as I am careful to not use the treeCache to add the node for the original get's Fqn, it works ok. ( Doing that would stick me in a recursive loop. )

          I was not sure if there was another intended approach such as a callback to the cache loader interceptor directly, for example.

          thanks

          • 2. Re: how to support custom CacheLoader callbacks to register
            Manik Surtani Master

            That would be the best way to do it. It does sound a bit odd and kludgy though, although it is a pretty unusual request. :-)

            There are no such callbacks in the cache loader interceptor.

            • 3. Re: how to support custom CacheLoader callbacks to register
              warren cooper Newbie

              Do you really think it is kludgy?

              The problem arises out of the fact that my cache loader impl is calling an external service that returns more data than I wish to store in a single node.

              I can put it in terms of the Student/ Course sample that comes with jboss-cache. ( The node names are overly simplified to make the point easier. ) :)

              Assume I have an object node bound to a fqn called /teacher/Jones/ and that 'get' results in a cache miss that triggers a call to my custom cache loader. What should I do if my custom loader call returns 'extra' data. Let's say it returns a set of students in addition to the teacher object.

              JBC works fine if I plan on stuffing the 'extra' data into the node's Map, but what if I want to bind that data? That would be reasonable in this case. I could see creating nodes for '/student/Brown' , '/student/Jones', etc...

              In my case, I am calling existing legacy services that happen to return this extra data in this fashion. I would think this could happen often in practice.

              /thanks

              • 4. Re: how to support custom CacheLoader callbacks to register
                Manik Surtani Master

                Still, odd that this is triggered by trying to load /teacher/Jones. I would expect the student data to be loaded lazily when accessed separately.

                • 5. Re: how to support custom CacheLoader callbacks to register
                  warren cooper Newbie

                  Sorry for the late reply...

                  >I would expect the student data to be loaded lazily when accessed >separately.

                  But what if the remote service that fetches this data was written to return additional data for the single call ( in the example above, I was suggesting that it would return both teach and student data ).

                  In my application this is the case. My custom cache loader impl fetches calls an existing external service call that returns additional data that I wish to define elsewhere in the cache under a separate node. ( Essentially, I am given flattened data and am normalizing it in the cache under separate nodes )

                  I would not want to make a service call from the cache loader impl that gives me all this data and then discard the 'extra' data until another cache miss (on a differnet fqn/node) for the 'extra' data leads to another invocation of the same service call.