com.github.benmanes.caffeine.cache.AsyncCache Java Examples

The following examples show how to use com.github.benmanes.caffeine.cache.AsyncCache. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CacheProvider.java    From caffeine with Apache License 2.0 5 votes vote down vote up
/** Returns a new cache generator. */
private static CacheGenerator newCacheGenerator(Method testMethod) {
  CacheSpec cacheSpec = testMethod.getAnnotation(CacheSpec.class);
  requireNonNull(cacheSpec, "@CacheSpec not found");
  Options options = Options.fromSystemProperties();

  // Inspect the test parameters for interface constraints (loading, async)
  boolean isAsyncOnly = hasCacheOfType(testMethod, AsyncCache.class);
  boolean isLoadingOnly =
      hasCacheOfType(testMethod, LoadingCache.class)
      || hasCacheOfType(testMethod, AsyncLoadingCache.class)
      || options.compute().filter(Compute.ASYNC::equals).isPresent();

  return new CacheGenerator(cacheSpec, options, isLoadingOnly, isAsyncOnly);
}
 
Example #2
Source File: CacheValidationListener.java    From caffeine with Apache License 2.0 5 votes vote down vote up
/** Free memory by clearing unused resources after test execution. */
private void cleanUp(ITestResult testResult) {
  boolean briefParams = !detailedParams.get();

  if (testResult.isSuccess() && briefParams) {
    testResult.setParameters(EMPTY_PARAMS);
    testResult.setThrowable(null);
  }

  Object[] params = testResult.getParameters();
  for (int i = 0; i < params.length; i++) {
    Object param = params[i];
    if ((param instanceof AsyncCache<?, ?>) || (param instanceof Cache<?, ?>)
        || (param instanceof Map<?, ?>) || (param instanceof Eviction<?, ?>)
        || (param instanceof Expiration<?, ?>) || (param instanceof VarExpiration<?, ?>)
        || ((param instanceof CacheContext) && briefParams)) {
      params[i] = simpleNames.get(param.getClass(), key -> ((Class<?>) key).getSimpleName());
    } else if (param instanceof CacheContext) {
      params[i] = simpleNames.get(param.toString(), Object::toString);
    } else {
      params[i] = Objects.toString(param);
    }
  }

  /*
  // Enable in TestNG 7.0
  if ((testResult.getName() != null) && briefParams) {
    testResult.setTestName(simpleNames.get(testResult.getName(), Object::toString));
  }
  */

  CacheSpec.interner.get().clear();
}
 
Example #3
Source File: CacheMetricsCollector.java    From client_java with Apache License 2.0 2 votes vote down vote up
/**
 * Add or replace the cache with the given name.
 * <p>
 * Any references any previous cache with this name is invalidated.
 *
 * @param cacheName The name of the cache, will be the metrics label value
 * @param cache The cache being monitored
 */
public void addCache(String cacheName, AsyncCache cache) {
    children.put(cacheName, cache.synchronous());
}