Package org.springframework.cache

Examples of org.springframework.cache.Cache


    return Collections.unmodifiableSet(this.cacheMap.keySet());
  }

  @Override
  public Cache getCache(String name) {
    Cache cache = this.cacheMap.get(name);
    if (cache == null && this.dynamic) {
      synchronized (this.cacheMap) {
        cache = this.cacheMap.get(name);
        if (cache == null) {
          cache = createGuavaCache(name);
View Full Code Here


   * @param context the invocation context
   * @return the cache to use (never null)
   */
  protected Cache resolveCache(CacheOperationInvocationContext<O> context) {
    Collection<? extends Cache> caches = context.getOperation().getCacheResolver().resolveCaches(context);
    Cache cache = extractFrom(caches);
    if (cache == null) {
      throw new IllegalStateException("Cache could not have been resolved for " + context.getOperation());
    }
    return cache;
  }
View Full Code Here

      throw ex;
    }
  }

  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);
  }
View Full Code Here

    }
  }

  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);
  }
View Full Code Here

    }
  }

  protected void cacheValue(CacheOperationInvocationContext<CachePutOperation> context, Object value) {
    Object key = generateKey(context);
    Cache cache = resolveCache(context);
    doPut(cache, key, value);
  }
View Full Code Here

      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();
View Full Code Here

   * (non-Javadoc)
   *
   * @see org.springframework.cache.CacheManager#getCache(java.lang.String)
   */
  public Cache getCache(String name) {
    Cache cache = caches.get(name);
    if (cache == null) {
      ImcacheCache newCache = new ImcacheCache(cacheBuilder.build(name));
      final Cache exCache = caches.putIfAbsent(name, newCache);
      if (exCache != null) {
        cache = exCache;
      } else {
        cache = newCache;
      }
View Full Code Here

   @Test
   public final void springRemoteCacheManagerShouldProperlyCreateCache() {
      final SpringRemoteCacheManager objectUnderTest = new SpringRemoteCacheManager(
            remoteCacheManager);

      final Cache defaultCache = objectUnderTest.getCache(TEST_CACHE_NAME);

      assertNotNull("getCache(" + TEST_CACHE_NAME
                          + ") should have returned a default cache. However, it returned null.", defaultCache);
      assertEquals("getCache(" + TEST_CACHE_NAME + ") should have returned a cache name \""
                         + TEST_CACHE_NAME + "\". However, the returned cache has a different name.",
                   TEST_CACHE_NAME, defaultCache.getName());
   }
View Full Code Here

            SpringEmbeddedCacheManagerTest.class
                  .getResourceAsStream(NAMED_ASYNC_CACHE_CONFIG_LOCATION));
      final SpringEmbeddedCacheManager objectUnderTest = new SpringEmbeddedCacheManager(
            nativeCacheManager);

      final Cache cacheExpectedToHaveTheProvidedName = objectUnderTest
            .getCache(CACHE_NAME_FROM_CONFIGURATION_FILE);

      assertEquals(
            "getCache("
                  + CACHE_NAME_FROM_CONFIGURATION_FILE
                  + ") should have returned the cache having the provided name. However, the cache returned has a different name.",
            CACHE_NAME_FROM_CONFIGURATION_FILE, cacheExpectedToHaveTheProvidedName.getName());
      nativeCacheManager.stop();
   }
View Full Code Here

            nativeCacheManager);

      final org.infinispan.Cache<Object, Object> infinispanCacheAddedLater = nativeCacheManager
            .getCache(nameOfInfinispanCacheAddedLater);

      final Cache springCacheAddedLater = objectUnderTest
            .getCache(nameOfInfinispanCacheAddedLater);

      assertEquals(
            "getCache("
                  + nameOfInfinispanCacheAddedLater
                  + ") should have returned the Spring cache having the Infinispan cache added after creating "
                  + "SpringEmbeddedCacheManager as its underlying native cache. However, the underlying native cache is different.",
            infinispanCacheAddedLater, springCacheAddedLater.getNativeCache());
      nativeCacheManager.stop();
   }
View Full Code Here

TOP

Related Classes of org.springframework.cache.Cache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.