org.springframework.cache.Cache.getName()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(176)

本文整理了Java中org.springframework.cache.Cache.getName()方法的一些代码示例,展示了Cache.getName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cache.getName()方法的具体详情如下:
包路径:org.springframework.cache.Cache
类名称:Cache
方法名:getName

Cache.getName介绍

[英]Return the cache name.
[中]返回缓存名称。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public String getName() {
  return this.targetCache.getName();
}

代码示例来源:origin: spring-projects/spring-framework

private Collection<String> createCacheNames(Collection<? extends Cache> caches) {
    Collection<String> names = new ArrayList<>();
    for (Cache cache : caches) {
      names.add(cache.getName());
    }
    return names;
  }
}

代码示例来源:origin: org.springframework/spring-context

private Collection<String> createCacheNames(Collection<? extends Cache> caches) {
    Collection<String> names = new ArrayList<>();
    for (Cache cache : caches) {
      names.add(cache.getName());
    }
    return names;
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Nullable
private Cache.ValueWrapper findInCaches(CacheOperationContext context, Object key) {
  for (Cache cache : context.getCaches()) {
    Cache.ValueWrapper wrapper = doGet(cache, key);
    if (wrapper != null) {
      if (logger.isTraceEnabled()) {
        logger.trace("Cache entry for key '" + key + "' found in cache '" + cache.getName() + "'");
      }
      return wrapper;
    }
  }
  return null;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Dynamically register an additional Cache with this manager.
 * @param cache the Cache to register
 * @deprecated as of Spring 4.3, in favor of {@link #getMissingCache(String)}
 */
@Deprecated
protected final void addCache(Cache cache) {
  String name = cache.getName();
  synchronized (this.cacheMap) {
    if (this.cacheMap.put(name, decorateCache(cache)) == null) {
      updateCacheNames(name);
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Initialize the static configuration of caches.
 * <p>Triggered on startup through {@link #afterPropertiesSet()};
 * can also be called to re-initialize at runtime.
 * @since 4.2.2
 * @see #loadCaches()
 */
public void initializeCaches() {
  Collection<? extends Cache> caches = loadCaches();
  synchronized (this.cacheMap) {
    this.cacheNames = Collections.emptySet();
    this.cacheMap.clear();
    Set<String> cacheNames = new LinkedHashSet<>(caches.size());
    for (Cache cache : caches) {
      String name = cache.getName();
      this.cacheMap.put(name, decorateCache(cache));
      cacheNames.add(name);
    }
    this.cacheNames = Collections.unmodifiableSet(cacheNames);
  }
}

代码示例来源:origin: spring-projects/spring-framework

protected void removeAll(CacheOperationInvocationContext<CacheRemoveAllOperation> context) {
  Cache cache = resolveCache(context);
  if (logger.isTraceEnabled()) {
    logger.trace("Invalidating entire cache '" + cache.getName() + "' for operation "
        + context.getOperation());
  }
  doClear(cache);
}

代码示例来源:origin: org.springframework/spring-context

@Nullable
private Cache.ValueWrapper findInCaches(CacheOperationContext context, Object key) {
  for (Cache cache : context.getCaches()) {
    Cache.ValueWrapper wrapper = doGet(cache, key);
    if (wrapper != null) {
      if (logger.isTraceEnabled()) {
        logger.trace("Cache entry for key '" + key + "' found in cache '" + cache.getName() + "'");
      }
      return wrapper;
    }
  }
  return null;
}

代码示例来源:origin: spring-projects/spring-framework

private void removeValue(CacheOperationInvocationContext<CacheRemoveOperation> context) {
  Object key = generateKey(context);
  Cache cache = resolveCache(context);
  if (logger.isTraceEnabled()) {
    logger.trace("Invalidating key [" + key + "] on cache '" + cache.getName()
        + "' for operation " + context.getOperation());
  }
  doEvict(cache, key);
}

代码示例来源:origin: org.springframework/spring-context

/**
 * Dynamically register an additional Cache with this manager.
 * @param cache the Cache to register
 * @deprecated as of Spring 4.3, in favor of {@link #getMissingCache(String)}
 */
@Deprecated
protected final void addCache(Cache cache) {
  String name = cache.getName();
  synchronized (this.cacheMap) {
    if (this.cacheMap.put(name, decorateCache(cache)) == null) {
      updateCacheNames(name);
    }
  }
}

代码示例来源:origin: org.springframework/spring-context-support

protected void removeAll(CacheOperationInvocationContext<CacheRemoveAllOperation> context) {
  Cache cache = resolveCache(context);
  if (logger.isTraceEnabled()) {
    logger.trace("Invalidating entire cache '" + cache.getName() + "' for operation "
        + context.getOperation());
  }
  doClear(cache);
}

代码示例来源:origin: org.springframework/spring-context-support

private void removeValue(CacheOperationInvocationContext<CacheRemoveOperation> context) {
  Object key = generateKey(context);
  Cache cache = resolveCache(context);
  if (logger.isTraceEnabled()) {
    logger.trace("Invalidating key [" + key + "] on cache '" + cache.getName()
        + "' for operation " + context.getOperation());
  }
  doEvict(cache, key);
}

代码示例来源:origin: spring-projects/spring-framework

@Bean
  public Cache mockErrorCache() {
    Cache cache = mock(Cache.class);
    given(cache.getName()).willReturn("error");
    return cache;
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Bean
public Cache mockCache() {
  Cache cache = mock(Cache.class);
  given(cache.getName()).willReturn("test");
  return cache;
}

代码示例来源:origin: spring-projects/spring-framework

@Bean
public Cache mockCache() {
  Cache cache = mock(Cache.class);
  given(cache.getName()).willReturn("test");
  return cache;
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testCacheName() throws Exception {
  assertEquals(CACHE_NAME, getCache().getName());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void resolveSimpleCache() throws Exception {
  DefaultCacheInvocationContext<?> dummyContext = createDummyContext();
  CacheResolverAdapter adapter = new CacheResolverAdapter(getCacheResolver(dummyContext, "testCache"));
  Collection<? extends Cache> caches = adapter.resolveCaches(dummyContext);
  assertNotNull(caches);
  assertEquals(1, caches.size());
  assertEquals("testCache", caches.iterator().next().getName());
}

代码示例来源:origin: spring-projects/spring-framework

assertEquals("test-resource-cache", cachingResolver.getCache().getName());
assertEquals("test-resource-cache", cachingTransformer.getCache().getName());

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testNoOpCache() throws Exception {
  String name = createRandomKey();
  Cache cache = this.manager.getCache(name);
  assertEquals(name, cache.getName());
  Object key = new Object();
  cache.put(key, new Object());
  assertNull(cache.get(key));
  assertNull(cache.get(key, Object.class));
  assertSame(cache, cache.getNativeCache());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void regularOperationsOnTarget() {
  Cache target = new ConcurrentMapCache("testCache");
  Cache cache = new TransactionAwareCacheDecorator(target);
  assertEquals(target.getName(), cache.getName());
  assertEquals(target.getNativeCache(), cache.getNativeCache());
  Object key = new Object();
  target.put(key, "123");
  assertEquals("123", cache.get(key).get());
  assertEquals("123", cache.get(key, String.class));
  cache.clear();
  assertNull(target.get(key));
}

相关文章