2

I have a method that returns the (rarely-changed) configuration of a system and want to cache it. The configuration is built from different pieces of data so I don't want to cache the individual pieces, but the SystemConfiguration object itself.

There is no argument to the method, how can I tell Ehcache to use a fixed key "configuration" (there's only one instance of the configuration)? Do I have to create a CacheKeyGenerator or is there a simpler method?

@CacheResult //how to specify the fixed key?
public SystemConfiguration getConfiguration() {
  return configuration; //this is a prebuilt object, as described
}
wishihadabettername
  • 14,231
  • 21
  • 68
  • 85

1 Answers1

2

Spring caching has a default key generation algorithm that will cover the use case of methods with no arguments.

However, if you want a specific value for the key then you need to implement your own generator.

Louis Jacomet
  • 13,661
  • 2
  • 34
  • 43
  • 1
    This is what I had to do; the default SimpleKey.EMPTY was not appropriate as I have several such cases besides just the SystemConfiguration object. – wishihadabettername May 11 '15 at 13:26