2 Replies Latest reply on Mar 29, 2007 9:56 AM by Fredrik Johansson


    Fredrik Johansson Newbie

      I'm using the 2.0 Habanero cache and I want to access my cache as a CacheSPI. The reason being that I want to access nodes as NodeSPI so I can inspect (and possible upgrade) the node lock.

      I started to check the Javadoc on how to get the CacheSPI instead of the regular Cache interface, but couldn't relly find anything. So I checked the test implementations for the 2.0, and found that you do this:

      cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(...);

      However, in the Javadoc we find:

      You should NEVER attempt to directly cast a Cache instance to this interface.

      ok, so I'm guessing that you want guys like me not to look at the unit tests and cast the Cache to a CacheSPI (because it may not work in the future) =)

      But, do you have any recommend way of getting a CacheSPI?
      Is there any other way then to make a cast at the moment?

        • 1. Re: CacheAPI
          Manik Surtani Master

          Remember that these tests are not how user code would typically interact with the library.

          Beyond that, I agree that eople would start referring to tests and copy stuff. A lot of the test cases were carried forward from the 1.x series where certain methods such as locks, etc. were available in TreeCache and these were used to test outcomes of operations. The quickest way to port the tests was to use a cast. In future this will go away, using proper mock objects or interceptors where possible, to inspect internals.

          The purpose of the SPIs are to provide an insight into the cache internals. Internals that are not needed for normal usage. These are available to people extending the cache or writing plugins, such as eviction policies, cache loaders and interceptors.

          If you are looking at changing the way locks work (upgrading if necessary) I'd recommend extending the PessimisticLockInterceptor.

          • 2. Re: CacheAPI
            Fredrik Johansson Newbie

            I'll look into the PessimisticLockInterceptor