4 Replies Latest reply on Dec 17, 2012 1:21 PM by rokhmanov

    Control translator cache behavior using Caching API

    rokhmanov

      Hi, I have a question about proper use of Caching API in custom translator. My much simplified task is to dynamically control caching for a specific model by some external parameter (for example by system load, or by some complex time algorythm). Would it be possible with just Caching API, without using cache hints or matviews?

      I did a quick look on Caching API, per my understanding I can enable caching in translator when my ExecutionFactory returns the properly built CacheDirective object by overriding the default getCacheDirective(). Can I modify the CacheDirective in my Execution? I've tried to modify CacheDirective obtained from ExecutionContext, but it seems causing no effect ( https://github.com/rokhmanov/teiid-test/tree/master/caching-api ). Am I doing somethign wrong?

       

      Thanks,

      Andriy

        • 1. Re: Control translator cache behavior using Caching API
          shawkins

          Your code and the Teiid unit tests works just fine for me.  You have the right idea.  By initializing a new CacheDirective to the user scope (or any non-none scope), you will buffer the results for caching until the final values of the directive are check to ensure that you still want the cache entry.

           

          So you are seeing two entries being created in your cache?  You can check the Teiid side of the logic in DataTierManagerImpl/CachingTupleSource.   The entry should be added in CachingTupleSource line 108, and then read by the next execution in DataTierManagerImpl.registerRequest.

           

          Perhaps your default infinispan-config.xml has been modified to not allow cache entries?

           

          Steve

          • 2. Re: Control translator cache behavior using Caching API
            rokhmanov

            Thanks Steve for advice. I was not completely clear with my problem. Please see updated code in GitHub - I've added a failing test case (it is currently @Ignored). The thing is that I want to change caching behavior between executions by manipulating CacheDirective.setScope() right in Execution class. I am not sure if I do it right.

            • 3. Re: Control translator cache behavior using Caching API
              shawkins

              Ah, it's much simplier of a problem then.  You're logic will never be hit in the Execution class since the criteria is not currently allowed to be pushed down.  Add compare criteria equals support and you should get the behavior you are looking for.

               

              Steve

              • 4. Re: Control translator cache behavior using Caching API
                rokhmanov

                That's what I missed. Thanks Steve!