-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GeneratedCacheKey implementation should be part of spec #313
Comments
Assigned this Eric. Can you write a test to illustrate. Would like to get this fixed for 1.1. |
Here is the test case showing that I have to use the GeneratedCacheKey implementation of the cdi integration module to actually retrieve the value from the cache: https://github.com/beikov/jsr107-313 |
I am not really an expert here and try to get into this, since nobody else seem to. So bare with me.
Does that mean one time you use String and one time you use Object as key type?
As far as I interpret it, either you specify it via the annotation Your test case only includes the |
Updated issue to "Question" since we first need to see what is affected here. |
Look, if you call a method annotated with @CacheResult as in my example, the interceptor puts a value into the underlying cache with a key of type |
We are talking about the Spec. The Spec defines:
As far as I understand it right now, if you do not specify So if you want to have a specific implementation, why don't you specify |
Ah, actually you said that by yourself:
Sorry, about that. |
I think your point is relevant, in general. There are a couple of things popping up, that all have to do with the interaction of the imperative API and annotations. Furthermore, there are always way to improve. However, JSR107 is in maintenance, we cannot change at this point to make it "nicer" which might break compatibility. If I did overlook something and some general things are wrong with the |
How is adding |
Late to the party, but IMO, the CacheKeyGenerator should have the specified 'generateCacheKey' return Object for the same reasons that java.util.HashMap.get(Object k) takes an Object as the paramter: the only thing that matters is that the object passed in object's .hashCode() and .equals() matches the item attempting to be found. The specific type doesn't matter. Now what I have to do is implement my own DefaultCacheKey implementation just like everyone else in the world. Which is code cruft which sorta makes me sad. |
I recently faced a situation where I use
@CacheResult
on a method with a string parameter. Another method which is annotated with@CachePut
or@CacheRemove
that uses an object as parameter will immediately bring up problems.The cache put/remove case will need a custom
CacheKeyGenerator
that extracts the string parameter of the object. The problem now is, that the cache key generator class has to return aGeneratedCacheKey
instance which will be used to find a cache entry. Since the implementation that is used in the cache result case is not necessarily known, we also have to create our own implementations forCacheKeyGenerator
andGeneratedCacheKey
and use the generator class everywhere instead of the default in order to have a compatible cache key for the cache put/remove case.I see 3 possible solutions
DefaultGeneratedCacheKey
implementation to the spec and specify that every implementation should use that class as defaultThe text was updated successfully, but these errors were encountered: