-
1. Re: How to access cache used by jcache annotations?
jimmy001 Nov 22, 2017 9:21 AM (in response to jimmy001)Well....
I don't like it, but the following snippet is able to lookup the value for result2:
public User findUserByAccountname(String username) throws AwinoEasyBaseException { User result0 = userDAO.getUserByUsername(username); CachingProvider cachingProvider = Caching.getCachingProvider(); Cache<Object, User> userCache = cachingProvider.getCacheManager().getCache(UserDAO.USER_CACHE_NAME); Object[] keyParams = new Object[1]; keyParams[0] = username; User result2 = userCache.get(new DefaultCacheKey(keyParams)); return result2; //return userDAO.getUserByUsername(username); }
-
2. Re: How to access cache used by jcache annotations?
sebastian.laskawiec Nov 28, 2017 3:29 AM (in response to jimmy001)Perhaps galder.zamarreno could correct me but I believe there is no contract between JCache API and EJB (Stateless beans are EJB, not CDI). Therefore the behavior is vendor-dependent or simply unpredictable.
I think you may want to migrate your application to CDI (you may see some test examples in out integration test package). Alternatively you may try to switch from @Stateless to @Singleton annotations. This way the container should return proper bean to our code. But as I said - that's vendor-dependent behavior.
-
3. Re: How to access cache used by jcache annotations?
jimmy001 Nov 29, 2017 11:30 AM (in response to sebastian.laskawiec)First I thought changing the EJBs to CDI Beans wouldn't help, but I was wrong. Works now correctly.
Thx for your advice.
-
4. Re: How to access cache used by jcache annotations?
christian.beikov Nov 30, 2017 5:13 AM (in response to jimmy001)I brought this issue up a long time ago, but the people didn't seem to care. Maybe someone can pressure them to rethink their decision?
GeneratedCacheKey implementation should be part of spec · Issue #313 · jsr107/jsr107spec · GitHub
As far as I am concerned, I use a custom cache key generator to avoid depending on the vendor specific cache key implementation. It's stupid but hopefully JCache 2.0 will get it right.
-
5. Re: How to access cache used by jcache annotations?
galder.zamarreno Dec 7, 2017 11:00 AM (in response to sebastian.laskawiec)That's correct Sebastian. JSR-107 was developed on its own and little efforts has been put into how the integration would work not only with EJBs, but other crucial parts such as JPA for second-level cache use cases.