Top Description Inners Fields Constructors Methods
org.springframework.cache.jcache.interceptor

public Class DefaultJCacheOperationSource

extends AnnotationJCacheOperationSource
implements BeanFactoryAware, SmartInitializingSingleton
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.Aware
Imports
java.util.Collection, java.util.function.Supplier, org.springframework.beans.BeanUtils, org.springframework.beans.factory.BeanFactory, .BeanFactoryAware, .NoSuchBeanDefinitionException, .NoUniqueBeanDefinitionException, .SmartInitializingSingleton, org.springframework.cache.Cache, .CacheManager, org.springframework.cache.interceptor.CacheOperationInvocationContext, .CacheResolver, .KeyGenerator, .SimpleCacheResolver, .SimpleKeyGenerator, org.springframework.lang.Nullable, org.springframework.util.Assert, org.springframework.util.function.SingletonSupplier, .SupplierUtils

The default JCacheOperationSource implementation delegating default operations to configurable services with sensible defaults when not present.
Authors
Stephane Nicoll, Juergen Hoeller
Since
4.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
DefaultJCacheOperationSource.LazyCacheResolver

Only resolve the default exception cache resolver when an exception needs to be handled.

Field Summary

Modifier and TypeField and Description
private final SingletonSupplier<KeyGenerator>
private BeanFactory
private SingletonSupplier<CacheManager>
private SingletonSupplier<CacheResolver>
private SingletonSupplier<CacheResolver>
private SingletonSupplier<KeyGenerator>

Constructor Summary

AccessConstructor and Description
public
DefaultJCacheOperationSource()

Construct a new DefaultJCacheOperationSource with the default key generator.

public
DefaultJCacheOperationSource(Supplier<CacheManager> cacheManager, Supplier<CacheResolver> cacheResolver, Supplier<CacheResolver> exceptionCacheResolver, Supplier<KeyGenerator> keyGenerator)

Construct a new DefaultJCacheOperationSource with the given cache manager, cache resolver and key generator suppliers, applying the corresponding default if a supplier is not resolvable.

Method Summary

Modifier and TypeMethod and Description
public void
afterSingletonsInstantiated()

Implements org.springframework.beans.factory.SmartInitializingSingleton.afterSingletonsInstantiated.

Invoked right at the end of the singleton pre-instantiation phase, with a guarantee that all regular singleton beans have been created already.

protected <T> T
getBean(Class<T>
the type of the bean to manage
type
)

Implements abstract org.springframework.cache.jcache.interceptor.AnnotationJCacheOperationSource.getBean.

Locate or create an instance of the specified cache strategy type.

public CacheManager
getCacheManager()

Return the specified cache manager to use, if any.

public CacheResolver
getCacheResolver()

Return the specified cache resolver to use, if any.

protected CacheManager
protected CacheResolver
protected CacheResolver
protected KeyGenerator
public CacheResolver
getExceptionCacheResolver()

Return the specified exception cache resolver to use, if any.

public KeyGenerator
getKeyGenerator()

Return the specified key generator to use.

public void
setBeanFactory(BeanFactory
owning BeanFactory (never null). The bean can immediately call methods on the factory.
beanFactory
)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Callback that supplies the owning factory to a bean instance.

public void
setCacheManager(CacheManager cacheManager)

Set the default CacheManager to use to lookup cache by name.

public void
setCacheResolver(CacheResolver cacheResolver)

Set the CacheResolver to resolve regular caches.

public void
setExceptionCacheResolver(CacheResolver exceptionCacheResolver)

Set the CacheResolver to resolve exception caches.

public void
setKeyGenerator(KeyGenerator keyGenerator)

Set the default KeyGenerator.

Inherited from org.springframework.cache.jcache.interceptor.AnnotationJCacheOperationSource:
createCachePutOperationcreateCacheRemoveAllOperationcreateCacheRemoveOperationcreateCacheResultOperationdetermineCacheNamedetermineCacheResolverFactorydetermineKeyGeneratorfindCacheOperationgenerateDefaultCacheNamegetCacheDefaultsgetCacheResolvergetExceptionCacheResolver

Field Detail

adaptedKeyGeneratorback to summary
private final SingletonSupplier<KeyGenerator> adaptedKeyGenerator
beanFactoryback to summary
private BeanFactory beanFactory
Annotations
@Nullable
cacheManagerback to summary
private SingletonSupplier<CacheManager> cacheManager
Annotations
@Nullable
cacheResolverback to summary
private SingletonSupplier<CacheResolver> cacheResolver
Annotations
@Nullable
exceptionCacheResolverback to summary
private SingletonSupplier<CacheResolver> exceptionCacheResolver
Annotations
@Nullable
keyGeneratorback to summary
private SingletonSupplier<KeyGenerator> keyGenerator

Constructor Detail

DefaultJCacheOperationSourceback to summary
public DefaultJCacheOperationSource()

Construct a new DefaultJCacheOperationSource with the default key generator.

See Also
SimpleKeyGenerator
DefaultJCacheOperationSourceback to summary
public DefaultJCacheOperationSource(Supplier<CacheManager> cacheManager, Supplier<CacheResolver> cacheResolver, Supplier<CacheResolver> exceptionCacheResolver, Supplier<KeyGenerator> keyGenerator)

Construct a new DefaultJCacheOperationSource with the given cache manager, cache resolver and key generator suppliers, applying the corresponding default if a supplier is not resolvable.

Since
5.1

Method Detail

afterSingletonsInstantiatedback to summary
public void afterSingletonsInstantiated()

Implements org.springframework.beans.factory.SmartInitializingSingleton.afterSingletonsInstantiated.

Doc from org.springframework.beans.factory.SmartInitializingSingleton.afterSingletonsInstantiated.

Invoked right at the end of the singleton pre-instantiation phase, with a guarantee that all regular singleton beans have been created already. ListableBeanFactory#getBeansOfType calls within this method won't trigger accidental side effects during bootstrap.

Note

This callback won't be triggered for singleton beans lazily initialized on demand after BeanFactory bootstrap, and not for any other bean scope either. Carefully use it for beans with the intended bootstrap semantics only.

Annotations
@Override
getBeanback to summary
protected <T> T getBean(Class<T> type)

Implements abstract org.springframework.cache.jcache.interceptor.AnnotationJCacheOperationSource.getBean.

Doc from org.springframework.cache.jcache.interceptor.AnnotationJCacheOperationSource.getBean.

Locate or create an instance of the specified cache strategy type.

Parameters
type:Class<T>

the type of the bean to manage

Returns:T

the required bean

Annotations
@Override
getCacheManagerback to summary
public CacheManager getCacheManager()

Return the specified cache manager to use, if any.

Annotations
@Nullable
getCacheResolverback to summary
public CacheResolver getCacheResolver()

Return the specified cache resolver to use, if any.

Annotations
@Nullable
getDefaultCacheManagerback to summary
protected CacheManager getDefaultCacheManager()
getDefaultCacheResolverback to summary
protected CacheResolver getDefaultCacheResolver()

Implements abstract org.springframework.cache.jcache.interceptor.AnnotationJCacheOperationSource.getDefaultCacheResolver.

Doc from org.springframework.cache.jcache.interceptor.AnnotationJCacheOperationSource.getDefaultCacheResolver.

Return the default CacheResolver if none is set.

Annotations
@Override
getDefaultExceptionCacheResolverback to summary
protected CacheResolver getDefaultExceptionCacheResolver()

Implements abstract org.springframework.cache.jcache.interceptor.AnnotationJCacheOperationSource.getDefaultExceptionCacheResolver.

Doc from org.springframework.cache.jcache.interceptor.AnnotationJCacheOperationSource.getDefaultExceptionCacheResolver.

Return the default exception CacheResolver if none is set.

Annotations
@Override
getDefaultKeyGeneratorback to summary
protected KeyGenerator getDefaultKeyGenerator()

Implements abstract org.springframework.cache.jcache.interceptor.AnnotationJCacheOperationSource.getDefaultKeyGenerator.

Doc from org.springframework.cache.jcache.interceptor.AnnotationJCacheOperationSource.getDefaultKeyGenerator.

Return the default KeyGenerator if none is set.

Annotations
@Override
getExceptionCacheResolverback to summary
public CacheResolver getExceptionCacheResolver()

Return the specified exception cache resolver to use, if any.

Annotations
@Nullable
getKeyGeneratorback to summary
public KeyGenerator getKeyGenerator()

Return the specified key generator to use.

setBeanFactoryback to summary
public void setBeanFactory(BeanFactory beanFactory)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Doc from org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Callback that supplies the owning factory to a bean instance.

Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean#afterPropertiesSet() or a custom init-method.

Parameters
beanFactory:BeanFactory

owning BeanFactory (never null). The bean can immediately call methods on the factory.

Annotations
@Override
setCacheManagerback to summary
public void setCacheManager(CacheManager cacheManager)

Set the default CacheManager to use to lookup cache by name. Only mandatory if the cache resolver has not been set.

setCacheResolverback to summary
public void setCacheResolver(CacheResolver cacheResolver)

Set the CacheResolver to resolve regular caches. If none is set, a default implementation using the specified cache manager will be used.

setExceptionCacheResolverback to summary
public void setExceptionCacheResolver(CacheResolver exceptionCacheResolver)

Set the CacheResolver to resolve exception caches. If none is set, a default implementation using the specified cache manager will be used.

setKeyGeneratorback to summary
public void setKeyGenerator(KeyGenerator keyGenerator)

Set the default KeyGenerator. If none is set, a SimpleKeyGenerator honoring the JSR-107 javax.cache.annotation.CacheKey and javax.cache.annotation.CacheValue will be used.

org.springframework.cache.jcache.interceptor back to summary

pack-priv Class DefaultJCacheOperationSource.LazyCacheResolver

extends Object
implements CacheResolver
Class Inheritance
  • java.lang.Object
  • org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource.LazyCacheResolver
All Implemented Interfaces
org.springframework.cache.interceptor.CacheResolver

Only resolve the default exception cache resolver when an exception needs to be handled.

A non-JSR-107 setup requires either a CacheManager or a CacheResolver. If only the latter is specified, it is not possible to extract a default exception CacheResolver from a custom CacheResolver implementation, so we have to fall back on the CacheManager.

This gives this weird situation of a perfectly valid configuration that breaks all of a sudden because the JCache support is enabled. To avoid this we resolve the default exception CacheResolver as late as possible to avoid such hard requirement in other cases.

Field Summary

Modifier and TypeField and Description
private final SingletonSupplier<CacheResolver>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Collection<? extends Cache>
resolveCaches(CacheOperationInvocationContext<?>
the context of the particular invocation
context
)

Implements org.springframework.cache.interceptor.CacheResolver.resolveCaches.

Return the cache(s) to use for the specified invocation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheResolverback to summary
private final SingletonSupplier<CacheResolver> cacheResolver

Constructor Detail

LazyCacheResolverback to summary
pack-priv LazyCacheResolver()

Method Detail

resolveCachesback to summary
public Collection<? extends Cache> resolveCaches(CacheOperationInvocationContext<?> context)

Implements org.springframework.cache.interceptor.CacheResolver.resolveCaches.

Doc from org.springframework.cache.interceptor.CacheResolver.resolveCaches.

Return the cache(s) to use for the specified invocation.

Parameters
context:CacheOperationInvocationContext<?>

the context of the particular invocation

Returns:Collection<? extends Cache>

the cache(s) to use (never null)

Annotations
@Override