-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
The default cache key for annotation API is not defined. The JCache JSR 107 only provides a way to generate the key of type GeneratedCacheKey, which implies that the default cache key must also implement that interface.
It is not easy to access a cache defined by annotations on methods with the programmatic API, as the default class of the key is unknown. It would help if it was possible to acquire a default instance of GeneratedCacheKey for varargs params matching the arguments to annotated methods.
The following does not work:
@Stateless
public class AnEJB {
@CacheResult
public String getResult(String key) { ... }
}
...
String valueViaAnnotation = anEJB.getResult(key);
String valueViaAPI = cache.get(key);
assertNotNull(valueViaAPI);
/* fails because the value is not stored under key, but under an instance of GeneratedCacheKey generated from key */
The following might work to get the value from cache programmatically, with defining a custom CacheKey generator:
String valueViaAnnotation = anEJB.getResult( key );
GeneratedCacheKey cacheKey = cacheService.getDefaultCacheKey( key );
String valueViaAPI = cache.get( cacheKey);
assertNotNull(valueViaAPI);
/* assertion passes, as the cacheService provides the same key as is generated during execution of anEJB.getResult( key ); */
Metadata
Metadata
Assignees
Labels
No labels