Codota Logo
CacheResultInterceptor
Code IndexAdd Codota to your IDE (free)

How to use
CacheResultInterceptor
in
org.springframework.cache.jcache.interceptor

Best Java code snippets using org.springframework.cache.jcache.interceptor.CacheResultInterceptor (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
ArrayList a =
  • Codota Iconnew ArrayList<String>()
  • Codota Iconnew ArrayList()
  • Codota Iconnew ArrayList<Object>()
  • Smart code suggestions by Codota
}
origin: spring-projects/spring-framework

@Override
@Nullable
protected Object invoke(
    CacheOperationInvocationContext<CacheResultOperation> context, CacheOperationInvoker invoker) {
  CacheResultOperation operation = context.getOperation();
  Object cacheKey = generateKey(context);
  Cache cache = resolveCache(context);
  Cache exceptionCache = resolveExceptionCache(context);
  if (!operation.isAlwaysInvoked()) {
    Cache.ValueWrapper cachedValue = doGet(cache, cacheKey);
    if (cachedValue != null) {
      return cachedValue.get();
    }
    checkForCachedException(exceptionCache, cacheKey);
  }
  try {
    Object invocationResult = invoker.invoke();
    doPut(cache, cacheKey, invocationResult);
    return invocationResult;
  }
  catch (CacheOperationInvoker.ThrowableWrapper ex) {
    Throwable original = ex.getOriginal();
    cacheException(exceptionCache, operation.getExceptionTypeFilter(), cacheKey, original);
    throw ex;
  }
}
origin: spring-projects/spring-framework

  Throwable exception, String className, String methodName) {
Throwable clone = cloneException(exception);
if (clone == null) {
  return new CacheOperationInvoker.ThrowableWrapper(exception);
StackTraceElement[] cachedCallStack = exception.getStackTrace();
int index = findCommonAncestorIndex(callStack, className, methodName);
int cachedIndex = findCommonAncestorIndex(cachedCallStack, className, methodName);
if (index == -1 || cachedIndex == -1) {
  return new CacheOperationInvoker.ThrowableWrapper(exception); // Cannot find common ancestor
origin: spring-projects/spring-framework

@Nullable
private Cache resolveExceptionCache(CacheOperationInvocationContext<CacheResultOperation> context) {
  CacheResolver exceptionCacheResolver = context.getOperation().getExceptionCacheResolver();
  if (exceptionCacheResolver != null) {
    return extractFrom(context.getOperation().getExceptionCacheResolver().resolveCaches(context));
  }
  return null;
}
origin: spring-projects/spring-framework

/**
 * Check for a cached exception. If the exception is found, throw it directly.
 */
protected void checkForCachedException(@Nullable Cache exceptionCache, Object cacheKey) {
  if (exceptionCache == null) {
    return;
  }
  Cache.ValueWrapper result = doGet(exceptionCache, cacheKey);
  if (result != null) {
    Throwable ex = (Throwable) result.get();
    Assert.state(ex != null, "No exception in cache");
    throw rewriteCallStack(ex, getClass().getName(), "invoke");
  }
}
origin: spring-projects/spring-framework

protected void cacheException(@Nullable Cache exceptionCache, ExceptionTypeFilter filter, Object cacheKey, Throwable ex) {
  if (exceptionCache == null) {
    return;
  }
  if (filter.match(ex.getClass())) {
    doPut(exceptionCache, cacheKey, ex);
  }
}
origin: spring-projects/spring-framework

public void afterPropertiesSet() {
  getCacheOperationSource();
  this.cacheResultInterceptor = new CacheResultInterceptor(getErrorHandler());
  this.cachePutInterceptor = new CachePutInterceptor(getErrorHandler());
  this.cacheRemoveEntryInterceptor = new CacheRemoveEntryInterceptor(getErrorHandler());
  this.cacheRemoveAllInterceptor = new CacheRemoveAllInterceptor(getErrorHandler());
  this.initialized = true;
}
origin: spring-projects/spring-framework

@SuppressWarnings("unchecked")
@Nullable
private Object execute(CacheOperationInvocationContext<?> context, CacheOperationInvoker invoker) {
  CacheOperationInvoker adapter = new CacheOperationInvokerAdapter(invoker);
  BasicOperation operation = context.getOperation();
  if (operation instanceof CacheResultOperation) {
    Assert.state(this.cacheResultInterceptor != null, "No CacheResultInterceptor");
    return this.cacheResultInterceptor.invoke(
        (CacheOperationInvocationContext<CacheResultOperation>) context, adapter);
  }
  else if (operation instanceof CachePutOperation) {
    Assert.state(this.cachePutInterceptor != null, "No CachePutInterceptor");
    return this.cachePutInterceptor.invoke(
        (CacheOperationInvocationContext<CachePutOperation>) context, adapter);
  }
  else if (operation instanceof CacheRemoveOperation) {
    Assert.state(this.cacheRemoveEntryInterceptor != null, "No CacheRemoveEntryInterceptor");
    return this.cacheRemoveEntryInterceptor.invoke(
        (CacheOperationInvocationContext<CacheRemoveOperation>) context, adapter);
  }
  else if (operation instanceof CacheRemoveAllOperation) {
    Assert.state(this.cacheRemoveAllInterceptor != null, "No CacheRemoveAllInterceptor");
    return this.cacheRemoveAllInterceptor.invoke(
        (CacheOperationInvocationContext<CacheRemoveAllOperation>) context, adapter);
  }
  else {
    throw new IllegalArgumentException("Cannot handle " + operation);
  }
}
origin: org.springframework/spring-context-support

/**
 * Check for a cached exception. If the exception is found, throw it directly.
 */
protected void checkForCachedException(@Nullable Cache exceptionCache, Object cacheKey) {
  if (exceptionCache == null) {
    return;
  }
  Cache.ValueWrapper result = doGet(exceptionCache, cacheKey);
  if (result != null) {
    Throwable ex = (Throwable) result.get();
    Assert.state(ex != null, "No exception in cache");
    throw rewriteCallStack(ex, getClass().getName(), "invoke");
  }
}
origin: org.springframework/spring-context-support

protected void cacheException(@Nullable Cache exceptionCache, ExceptionTypeFilter filter, Object cacheKey, Throwable ex) {
  if (exceptionCache == null) {
    return;
  }
  if (filter.match(ex.getClass())) {
    doPut(exceptionCache, cacheKey, ex);
  }
}
origin: org.springframework/spring-context-support

public void afterPropertiesSet() {
  getCacheOperationSource();
  this.cacheResultInterceptor = new CacheResultInterceptor(getErrorHandler());
  this.cachePutInterceptor = new CachePutInterceptor(getErrorHandler());
  this.cacheRemoveEntryInterceptor = new CacheRemoveEntryInterceptor(getErrorHandler());
  this.cacheRemoveAllInterceptor = new CacheRemoveAllInterceptor(getErrorHandler());
  this.initialized = true;
}
origin: org.springframework/spring-context-support

@SuppressWarnings("unchecked")
@Nullable
private Object execute(CacheOperationInvocationContext<?> context, CacheOperationInvoker invoker) {
  CacheOperationInvoker adapter = new CacheOperationInvokerAdapter(invoker);
  BasicOperation operation = context.getOperation();
  if (operation instanceof CacheResultOperation) {
    Assert.state(this.cacheResultInterceptor != null, "No CacheResultInterceptor");
    return this.cacheResultInterceptor.invoke(
        (CacheOperationInvocationContext<CacheResultOperation>) context, adapter);
  }
  else if (operation instanceof CachePutOperation) {
    Assert.state(this.cachePutInterceptor != null, "No CachePutInterceptor");
    return this.cachePutInterceptor.invoke(
        (CacheOperationInvocationContext<CachePutOperation>) context, adapter);
  }
  else if (operation instanceof CacheRemoveOperation) {
    Assert.state(this.cacheRemoveEntryInterceptor != null, "No CacheRemoveEntryInterceptor");
    return this.cacheRemoveEntryInterceptor.invoke(
        (CacheOperationInvocationContext<CacheRemoveOperation>) context, adapter);
  }
  else if (operation instanceof CacheRemoveAllOperation) {
    Assert.state(this.cacheRemoveAllInterceptor != null, "No CacheRemoveAllInterceptor");
    return this.cacheRemoveAllInterceptor.invoke(
        (CacheOperationInvocationContext<CacheRemoveAllOperation>) context, adapter);
  }
  else {
    throw new IllegalArgumentException("Cannot handle " + operation);
  }
}
origin: org.springframework/spring-context-support

@Override
@Nullable
protected Object invoke(
    CacheOperationInvocationContext<CacheResultOperation> context, CacheOperationInvoker invoker) {
  CacheResultOperation operation = context.getOperation();
  Object cacheKey = generateKey(context);
  Cache cache = resolveCache(context);
  Cache exceptionCache = resolveExceptionCache(context);
  if (!operation.isAlwaysInvoked()) {
    Cache.ValueWrapper cachedValue = doGet(cache, cacheKey);
    if (cachedValue != null) {
      return cachedValue.get();
    }
    checkForCachedException(exceptionCache, cacheKey);
  }
  try {
    Object invocationResult = invoker.invoke();
    doPut(cache, cacheKey, invocationResult);
    return invocationResult;
  }
  catch (CacheOperationInvoker.ThrowableWrapper ex) {
    Throwable original = ex.getOriginal();
    cacheException(exceptionCache, operation.getExceptionTypeFilter(), cacheKey, original);
    throw ex;
  }
}
origin: apache/servicemix-bundles

/**
 * Check for a cached exception. If the exception is found, throw it directly.
 */
protected void checkForCachedException(Cache exceptionCache, Object cacheKey) {
  if (exceptionCache == null) {
    return;
  }
  Cache.ValueWrapper result = doGet(exceptionCache, cacheKey);
  if (result != null) {
    throw rewriteCallStack((Throwable) result.get(), getClass().getName(), "invoke");
  }
}
origin: org.springframework/spring-context-support

  Throwable exception, String className, String methodName) {
Throwable clone = cloneException(exception);
if (clone == null) {
  return new CacheOperationInvoker.ThrowableWrapper(exception);
StackTraceElement[] cachedCallStack = exception.getStackTrace();
int index = findCommonAncestorIndex(callStack, className, methodName);
int cachedIndex = findCommonAncestorIndex(cachedCallStack, className, methodName);
if (index == -1 || cachedIndex == -1) {
  return new CacheOperationInvoker.ThrowableWrapper(exception); // Cannot find common ancestor
origin: apache/servicemix-bundles

protected void cacheException(Cache exceptionCache, ExceptionTypeFilter filter, Object cacheKey, Throwable ex) {
  if (exceptionCache == null) {
    return;
  }
  if (filter.match(ex.getClass())) {
    doPut(exceptionCache, cacheKey, ex);
  }
}
origin: org.springframework/spring-context-support

@Nullable
private Cache resolveExceptionCache(CacheOperationInvocationContext<CacheResultOperation> context) {
  CacheResolver exceptionCacheResolver = context.getOperation().getExceptionCacheResolver();
  if (exceptionCacheResolver != null) {
    return extractFrom(context.getOperation().getExceptionCacheResolver().resolveCaches(context));
  }
  return null;
}
origin: apache/servicemix-bundles

public void afterPropertiesSet() {
  Assert.state(getCacheOperationSource() != null, "The 'cacheOperationSource' property is required: " +
      "If there are no cacheable methods, then don't use a cache aspect.");
  Assert.state(getErrorHandler() != null, "The 'errorHandler' property is required");
  this.cacheResultInterceptor = new CacheResultInterceptor(getErrorHandler());
  this.cachePutInterceptor = new CachePutInterceptor(getErrorHandler());
  this.cacheRemoveEntryInterceptor = new CacheRemoveEntryInterceptor(getErrorHandler());
  this.cacheRemoveAllInterceptor = new CacheRemoveAllInterceptor(getErrorHandler());
  this.initialized = true;
}
origin: apache/servicemix-bundles

return this.cachePutInterceptor.invoke(
    (CacheOperationInvocationContext<CachePutOperation>) context, adapter);
return this.cacheRemoveEntryInterceptor.invoke(
    (CacheOperationInvocationContext<CacheRemoveOperation>) context, adapter);
return this.cacheRemoveAllInterceptor.invoke(
    (CacheOperationInvocationContext<CacheRemoveAllOperation>) context, adapter);
origin: apache/servicemix-bundles

@Override
protected Object invoke(CacheOperationInvocationContext<CacheResultOperation> context,
    CacheOperationInvoker invoker) {
  CacheResultOperation operation = context.getOperation();
  Object cacheKey = generateKey(context);
  Cache cache = resolveCache(context);
  Cache exceptionCache = resolveExceptionCache(context);
  if (!operation.isAlwaysInvoked()) {
    Cache.ValueWrapper cachedValue = doGet(cache, cacheKey);
    if (cachedValue != null) {
      return cachedValue.get();
    }
    checkForCachedException(exceptionCache, cacheKey);
  }
  try {
    Object invocationResult = invoker.invoke();
    doPut(cache, cacheKey, invocationResult);
    return invocationResult;
  }
  catch (CacheOperationInvoker.ThrowableWrapper ex) {
    Throwable original = ex.getOriginal();
    cacheException(exceptionCache, operation.getExceptionTypeFilter(), cacheKey, original);
    throw ex;
  }
}
origin: apache/servicemix-bundles

  Throwable exception, String className, String methodName) {
Throwable clone = cloneException(exception);
if (clone == null) {
  return new CacheOperationInvoker.ThrowableWrapper(exception);
StackTraceElement[] cachedCallStack = exception.getStackTrace();
int index = findCommonAncestorIndex(callStack, className, methodName);
int cachedIndex = findCommonAncestorIndex(cachedCallStack, className, methodName);
if (index == -1 || cachedIndex == -1) {
  return new CacheOperationInvoker.ThrowableWrapper(exception); // Cannot find common ancestor
org.springframework.cache.jcache.interceptorCacheResultInterceptor

Javadoc

Intercept methods annotated with CacheResult.

Most used methods

  • <init>
  • cacheException
  • checkForCachedException
    Check for a cached exception. If the exception is found, throw it directly.
  • cloneException
  • doGet
  • doPut
  • extractFrom
  • findCommonAncestorIndex
  • generateKey
  • invoke
  • resolveCache
  • resolveExceptionCache
  • resolveCache,
  • resolveExceptionCache,
  • rewriteCallStack

Popular in Java

  • Start an intent from android
  • setRequestProperty (URLConnection)
  • scheduleAtFixedRate (ScheduledExecutorService)
    Creates and executes a periodic action that becomes enabled first after the given initial delay, and
  • orElseThrow (Optional)
  • BufferedInputStream (java.io)
    Wraps an existing InputStream and buffers the input. Expensive interaction with the underlying input
  • PrintStream (java.io)
    A PrintStream adds functionality to another output stream, namely the ability to print representatio
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • LoggerFactory (org.slf4j)
    The LoggerFactory is a utility class producing Loggers for various logging APIs, most notably for lo
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now