3 Replies Latest reply on Apr 7, 2005 9:10 AM by Bela Ban

    Using pre-configured CacheLoader

    Adam Kropp Newbie

      I am using the Spring Framework to configure all of my business objects, including an instance of TreeCache (rather than using MBeans). I was hoping to be able to create a CacheLoader bean in my Spring configuration xml file which I can set as the CacheLoader property on the TreeCache.

      This approach sort of works (the CacheLoader gets set properly, and the CacheLoaderIntercepter properly delegates the get methods to my class), however TreeCache doesn't initialize my loader. Specifically, it doesn't call setConfig(), setCache(), create(), or start(). I don't have a problem with it not calling setConfig() or create() (these should probably only be called when the CacheLoader is created and configured by TreeCache), but it seems like it should always call setCache() on the CacheLoader, and it should probably call start() in notifyCacheStarted() or in startService().

      I have a feeling the intention was to always provide CacheLoaderClass and CacheLoaderConfig, but in my case, it is much more convenient to pass in an already created/configured CacheLoader, and still have TreeCache behave properly.

      I can provide a patch for how I think it should behave, but wanted to get color on why it behaves the way it does now.

        • 1. Re: Using pre-configured CacheLoader
          Bela Ban Master

          I changed this in CVS head: here's the new method (called in startService()):
          protected void createCacheLoader() throws Exception {
          if(cache_loader == null && cache_loader_class != null) {
          Class cl=Thread.currentThread().getContextClassLoader().loadClass(cache_loader_class);
          cache_loader=(CacheLoader)cl.newInstance();
          }
          cache_loader.setConfig(cache_loader_config);
          cache_loader.setCache(this);
          cache_loader.create();
          cache_loader.start();
          }

          • 2. Re: Using pre-configured CacheLoader
            Adam Kropp Newbie

            That will do it. Thanks.

            • 3. Re: Using pre-configured CacheLoader
              Bela Ban Master

              Actually, do another cvs update, because that code caused an NPE, the real code is:
              protected void createCacheLoader() throws Exception {
              if(cache_loader == null && cache_loader_class != null) {
              Class cl=Thread.currentThread().getContextClassLoader().loadClass(cache_loader_class);
              cache_loader=(CacheLoader)cl.newInstance();
              }
              if(cache_loader != null) {
              cache_loader.setConfig(cache_loader_config);
              cache_loader.setCache(this);
              cache_loader.create();
              cache_loader.start();
              }
              }