deem
deem

Reputation: 1252

how to cache other methods from the same class?

I'm using Ehcache implementation of JCache.

Lets say, I've class Test. In this class I've two methods: methodA and methodB. methodB has annotation @CacheResult(cacheName = "methodB").

From this informations you would guess that I'd like to have cached method methodB and methodA should use this cache.

But... It does not work. When I'm using methods from the same class, it seems like this annotation is not firing its interceptor. It works though if I create class Test2 and move method methodB to this class - then, as expected, the result of this method is cached.

How can I enable caching methods from the same class?

Upvotes: 0

Views: 1362

Answers (1)

deem
deem

Reputation: 1252

As for now, it seems impossible - if we stick to CacheResult annotations.

This is because interceptors are not fired correctly when class is using its methods by this reference - and not by CDI. If we want to cache them, we need to use another way or just call some static method, lets say cacheMe, inside every private method.

Upvotes: 2

Related Questions