-
Couldn't load subscription status.
- Fork 38.8k
Description
Travis Schneeberger opened SPR-9525 and commented
We are using the Spring Cache Abstraction pretty heavily. One of the standards we have adopted is always placing cache annotations on the service interface. This allow various implementations of a service to have caching whether the implementation is hand coded, a remote proxy, etc.
For example:
public interface FooService {
@Cacheable(value=Foo, key="'firstArg=' + #firstArg + '|' + 'secondArg=' + #secondArg")
Foo getFoo(String firstArg, String secondArg);
}
Many times we are finding that Spring is literally using the following as the cache key:
firstArg=#firstArg|secondArg=#secondArg
This is obviously problematic because everything will generate the same cachekey making caching completely broken.
This happens when Spring cannot find the argument names on the method that spring is proxying for caching. I suspect this is happening when the spring caching proxy is proxying another proxy (for remoting for example) and that proxy is not keeping the method variable names in tact.
It would be nice is spring would throw an exception or at least log an error when parsing a spring expression referencing argument (or other implicit variables ex: root.methodName) names that do not exist. Throwing an exception would be preferred because in the case of caching, this is a hard error.
As a work around for this problem we are doing the following which always works:
public interface FooService {
@Cacheable(value=Foo, key="'firstArg=' + #p0 + '|' + 'secondArg=' + #p1")
Foo getFoo(String firstArg, String secondArg);
}
The added benefit of this approach is it can be used without debug symbols. We probably will not switch back to using real parameter names in our SpEl but for the benefit of the community, I figured I file a jira.
Affects: 3.1 GA
Reference URL: https://jira.kuali.org/browse/KULRICE-7514
Issue Links:
- Generics and caching causing issues [SPR-13358] #17942 Generics and caching causing issues