0

I am working on setting up Spring Cache support for my Java application. I want a way to set a global @CacheConfig for my entire project because I want all cache operations in the application to use the exact same cache name and custom KeyGenerator implementation. I was hoping that I could annotate some global configuration class or my CacheManager with @CacheConfig, but it looks like @CacheConfig is only meant as configuration for the class of the method with the Cache Annotation. Thus, I would need to use the same exact @CacheConfig annotation definition for every class using Spring Cache operations.

A workaround that I'm going to use in the meanwhile is implement my own meta-annotation of Spring Cache annotations such as @Cacheable, so that the same exact name and keyGenerator will be used for all cache operations. But, there must be a better way to do this than using custom annotations. If I ever run into the situation where I want to use a Cache named something other than "default", then I'm going to run into trouble with my custom annotation.

Any ideas? Thank you.

ecbrodie
  • 11,246
  • 21
  • 71
  • 120

1 Answers1

2

Yes, this is doable.

All you need is to populate AnnotationCacheOperationSource with your own CacheAnnotationParser, see how is it done by default: SpringCacheAnnotationParser.

Unfortunately I can't provide you with code snippets, my Spring-fu is too weak at this moment. If you manage to get this working - let me know.

Trynkiewicz Mariusz
  • 2,722
  • 3
  • 21
  • 27