-
Notifications
You must be signed in to change notification settings - Fork 165
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
Interactions between declarative API and CacheLoader&CacheWriter? #375
Comments
Why should it? That is actually the very concept of a cache key and the IMHO the JavaDoc of the Of course the loader might want to get an additional setup that is immutable during the cache live time. But "passing down" such a setup by method parameters would be very error prone. Is there really a useful scenario for |
@CacheResult
Person calculateArchenemy(Person person) {
if (person.equals(Person.HOLMES)) {
return Person.MORIARTY;
} else {
return expensiveCalculation(person.getId());
}
} Now imagine I have a database dump of archenemies of all people in the world. Then I could just plug the |
Got you. The main issue is the Mixing Loader/Writer and annotation will get you also in other troubles as well: Annotations have (defined) exception handling, while loaders don't. |
this is related: #374 <-- if this is going to be implemented then the key could be truly everything. I also found this and this is partially related as well. The original idea behind this issue comes from ben-manes/caffeine#115 |
Marking with 2.0. The key generation stuff can be improved but not in the 1.1 MR. |
When a declarative API (cache annotations) is used then a container generates a cache key.
When a cache is configured as read-through or write-through then the generated key is passed to a CacheLoader/CacheWriter.
However there is a mismatch: The key is generated by a container however the CacheLoader/CacheWriter are typically implemented by end-users -> the
CacheLoader
has no good way to access arguments used during invocation of the annotated method. All it has is just the generated key.A possible workaround is to always always use an explicit
CacheKeyGenerator
and never use the default one -> a user has a full control of the generated cache key and can get back the arguments in theMapLoader
code. Unfortunately this is tedious asCacheKeyGenerator
is a very low-level API and it renders the default generator useless.I'm not sure what's the best solution here:
The implementation could have an extra method to get back the arguments encapsulated by this key? However this approach goes against the idea of generated key relaxation.
Related to #313
The text was updated successfully, but these errors were encountered: