can we have recommendations for all of the variations of ways to import CacheManager in a plugin?
Sorry if this thread has been confusing. Let me summarise the implications of CACHE-240 for importing the CacheManager
service from OSGi:
- If you import it via an
<component-import>
element inatlassian-plugin.xml
, you’re safe. - If you import it via Spring Scanner’s
@ComponentImport
annotation, you’re safe. - If you import it via Spring Java Config, then you need to use
@Bean(destroyMethod="")
instead of just@Bean
in your configuration class, otherwise your app will shut down the importedCacheManager
if your app is ever disabled or uninstalled.
Unfortunately there’s no way to make CacheManager
unconditionally “safe” for apps to use, because it needs to have the “dangerous” shutdown
method so that the product can legitimately shut it down. The CacheFactory
API was explicitly designed to be the safe way for apps to create a cache. It’s regrettable that Confluence app developers have no choice but to use CacheManager
(noting that they can use the fix described above). As far as I know, apps for other products can quite happily use CacheFactory
. So to put this problem in perspective, CACHE-240 only affects apps that run in Confluence AND use Spring Java Config (and for that edge case, use the above workaround).
Changing the public API isn’t an option, that’s a recipe for trouble. The workaround described above will need to be used until Confluence provides a CacheFactory
implementation that’s suitable for apps to use (and updates their doco accordingly). Let me repeat that this only relates to a tiny fraction of apps, noting that we only announced Spring Java Config late last year.