Package org.springframework.cache

Examples of org.springframework.cache.Cache


        Long id = 1L;
        User user = new User(id, "zhang", "zhang@gmail.com");

        //根据缓存名字获取Cache
        Cache cache = cacheCacheManager.getCache("user");
        //往缓存写数据
        cache.put(id, user);
        //从缓存读数据
        Assert.assertNotNull(cache.get(id, User.class));
    }
View Full Code Here


    protected Collection<? extends Cache> getCaches(CacheOperation operation) {
        Set<String> cacheNames = operation.getCacheNames();
        Collection<Cache> caches = new ArrayList<Cache>(cacheNames.size());
        for (String cacheName : cacheNames) {
            Cache cache = this.cacheManager.getCache(cacheName);
            Assert.notNull(cache, "Cannot find cache named '" + cacheName + "' for " + operation);
            caches.add(cache);
        }
        return caches;
    }
View Full Code Here

      return Collections.emptyList();
    }
    else {
      Collection<Cache> result = new ArrayList<Cache>();
      for (String cacheName : cacheNames) {
        Cache cache = this.cacheManager.getCache(cacheName);
        if (cache == null) {
          throw new IllegalArgumentException("Cannot find cache named '" +
              cacheName + "' for " + context.getOperation());
        }
        result.add(cache);
View Full Code Here


  @Override
  public Cache getCache(String name) {
    for (CacheManager cacheManager : this.cacheManagers) {
      Cache cache = cacheManager.getCache(name);
      if (cache != null) {
        return cache;
      }
    }
    return null;
View Full Code Here

  // Lazy cache initialization on access

  @Override
  public Cache getCache(String name) {
    Cache cache = lookupCache(name);
    if (cache != null) {
      return cache;
    }
    else {
      Cache missingCache = getMissingCache(name);
      if (missingCache != null) {
        addCache(missingCache);
        return lookupCache(name)// may be decorated
      }
      return null;
View Full Code Here

   * This implementation always returns a {@link Cache} implementation that will not store items.
   * Additionally, the request cache will be remembered by the manager for consistency.
   */
  @Override
  public Cache getCache(String name) {
    Cache cache = this.caches.get(name);
    if (cache == null) {
      this.caches.putIfAbsent(name, new NoOpCache(name));
      synchronized (this.cacheNames) {
        this.cacheNames.add(name);
      }
View Full Code Here

    Object r10 = service.cache(o2);

    assertSame(r1, r2);
    assertNotSame(r1, r10);
    service.evictAll(new Object());
    Cache cache = cm.getCache("testCache");
    assertNull(cache.get(o1));
    assertNull(cache.get(o2));

    Object r3 = service.cache(o1);
    Object r4 = service.cache(o1);
    assertNotSame(r1, r3);
    assertSame(r3, r4);
View Full Code Here

    assertSame(r3, r4);
  }

  public void testUnlessExpression(CacheableService<?> service) throws Exception {
    Cache cache = cm.getCache("testCache");
    cache.clear();
    service.unless(10);
    service.unless(11);
    assertThat(cache.get(10).get(), equalTo((Object) 10L));
    assertThat(cache.get(11), nullValue());
  }
View Full Code Here

  public void testMethodName(CacheableService<?> service, String keyName) throws Exception {
    Object key = new Object();
    Object r1 = service.name(key);
    assertSame(r1, service.name(key));
    Cache cache = cm.getCache("testCache");
    // assert the method name is used
    assertNotNull(cache.get(keyName));
  }
View Full Code Here

  public void testRootVars(CacheableService<?> service) {
    Object key = new Object();
    Object r1 = service.rootVars(key);
    assertSame(r1, service.rootVars(key));
    Cache cache = cm.getCache("testCache");
    // assert the method name is used
    String expectedKey = "rootVarsrootVars" + AopProxyUtils.ultimateTargetClass(service) + service;
    assertNotNull(cache.get(expectedKey));
  }
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.