当前位置: 首页>>代码示例>>Java>>正文


Java Cache类代码示例

本文整理汇总了Java中org.springframework.cache.Cache的典型用法代码示例。如果您正苦于以下问题:Java Cache类的具体用法?Java Cache怎么用?Java Cache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Cache类属于org.springframework.cache包,在下文中一共展示了Cache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setCaches

import org.springframework.cache.Cache; //导入依赖的package包/类
public void setCaches(Collection<Cache> caches) {
    if (CollectionUtils.isNotEmpty(caches)) {
        for (Cache cache : caches) {
            this.caches.put(cache.getName(), cache);
        }
    }
}
 
开发者ID:m18507308080,项目名称:bohemia,代码行数:8,代码来源:CachesManager.java

示例2: testPut

import org.springframework.cache.Cache; //导入依赖的package包/类
@Test
public void testPut() throws Exception {
    Cache proxy = new ConcurrentMapCache("foo");
    proxy.put("bar", "value");
    proxy.put("baz", "value");
    FluuzCache fluuzCache = new FluuzCache(eventManager, proxy);
    eventManager.register(fluuzCache);
    Thread.sleep(2000);

    eventManager.evict("foo", "bar");

    Thread.sleep(2000);

    String value = null;
    ValueWrapper vw = proxy.get("bar");
    if (vw == null) {

    }
    System.out.println("->" + value);
}
 
开发者ID:ArawakCC,项目名称:fluuz,代码行数:21,代码来源:RedisEventManagerTest.java

示例3: getCache

import org.springframework.cache.Cache; //导入依赖的package包/类
@Override
public Cache getCache(String name) {
    Cache cache = instanceMap.get(name);
    if (cache != null) {
        return cache;
    }
    if (!dynamic) {
        return cache;
    }
    
    CacheConfig config = configMap.get(name);
    if (config == null) {
        config = createDefaultConfig();
        configMap.put(name, config);
    }
    
    if (config.getMaxIdleTime() == 0 && config.getTTL() == 0 && config.getMaxSize() == 0) {
        return createMap(name, config);
    }
    
    return createMapCache(name, config);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:23,代码来源:RedissonSpringCacheManager.java

示例4: cachesValuesReturnedForQueryMethod

import org.springframework.cache.Cache; //导入依赖的package包/类
@Test
public void cachesValuesReturnedForQueryMethod() {

	User dave = new User();
	dave.setUsername("dmatthews");

	dave = repository.save(dave);

	User result = repository.findByUsername("dmatthews");
	assertThat(result, is(dave));

	// Verify entity cached
	Cache cache = cacheManager.getCache("byUsername");
	ValueWrapper wrapper = cache.get("dmatthews");
	assertThat(wrapper.get(), is((Object) dave));
}
 
开发者ID:Just-Fun,项目名称:spring-data-examples,代码行数:17,代码来源:CachingRepositoryTests.java

示例5: updateCache

import org.springframework.cache.Cache; //导入依赖的package包/类
@AfterReturning ("@annotation(fr.gael.dhus.spring.cache.IncrementCache)")
public void updateCache (JoinPoint joinPoint)
{
   IncrementCache annotation = ((MethodSignature) joinPoint.getSignature ())
         .getMethod ().getAnnotation (IncrementCache.class);

   Cache cache = getCacheManager().getCache(annotation.name());
   if (cache != null)
   {
      synchronized (cache)
      {
         Integer old_value = cache.get (annotation.key (), Integer.class);
         cache.clear ();
         if (old_value == null)
         {
            return;
         }
         cache.put (annotation.key (), (old_value + annotation.value ()));
      }
   }
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:22,代码来源:CacheAspectDefinition.java

示例6: performCacheEvict

import org.springframework.cache.Cache; //导入依赖的package包/类
private void performCacheEvict(CacheOperationContext context, CacheEvictOperation operation, Object result) {
	Object key = null;
	for (Cache cache : context.getCaches()) {
		if (operation.isCacheWide()) {
			logInvalidating(context, operation, null);
			cache.clear();
		}
		else {
			if (key == null) {
				key = context.generateKey(result);
			}
			logInvalidating(context, operation, key);
			cache.evict(key);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:CacheAspectSupport.java

示例7: loadCaches

import org.springframework.cache.Cache; //导入依赖的package包/类
@Override
protected Collection<Cache> loadCaches() {
	net.sf.ehcache.CacheManager cacheManager = getCacheManager();
	Assert.notNull(cacheManager, "A backing EhCache CacheManager is required");
	Status status = cacheManager.getStatus();
	Assert.isTrue(Status.STATUS_ALIVE.equals(status),
			"An 'alive' EhCache CacheManager is required - current cache is " + status.toString());

	String[] names = cacheManager.getCacheNames();
	Collection<Cache> caches = new LinkedHashSet<Cache>(names.length);
	for (String name : names) {
		caches.add(new EhCacheCache(cacheManager.getEhcache(name)));
	}
	return caches;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:EhCacheCacheManager.java

示例8: findUsersByUsername

import org.springframework.cache.Cache; //导入依赖的package包/类
@Override
public Users findUsersByUsername(String username) {

    final Cache usersCache = getUsersCache();

    final String key = generateUsersKey(username);
    Users users = (Users) getFromCache(usersCache, key);

    if (users == null) {
        users = usersRepository.findUsersByUsername(username);
        putToCache(usersCache, key, users);
        LOG.debug("Load Users[{}] from DB and cache it, key = {}", users, key);
    }

    return users;
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro-redis,代码行数:17,代码来源:UsersRSRedisRepository.java

示例9: findRolesByUsername

import org.springframework.cache.Cache; //导入依赖的package包/类
@Override
public List<Roles> findRolesByUsername(String username) {

    final Cache usersCache = getUsersCache();

    final String key = generateUserRolesKey(username);
    @SuppressWarnings("unchecked")
    List<Roles> rolesList = (List<Roles>) getFromCache(usersCache, key);

    if (rolesList == null) {
        rolesList = usersRepository.findRolesByUsername(username);
        putToCache(usersCache, key, rolesList);
        LOG.debug("Load User roles[{}] from DB and cache it, key = {}", rolesList, key);
    }

    return rolesList;
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro-redis,代码行数:18,代码来源:UsersRSRedisRepository.java

示例10: findAccessTokenByTokenId

import org.springframework.cache.Cache; //导入依赖的package包/类
@Override
public AccessToken findAccessTokenByTokenId(String tokenId) {

    final Cache accessTokenCache = getAccessTokenCache();

    final String key = generateAccessTokenKey(tokenId);
    AccessToken accessToken = (AccessToken) getFromCache(accessTokenCache, key);

    if (accessToken == null) {
        accessToken = oAuthRSRepository.findAccessTokenByTokenId(tokenId);
        putToCache(accessTokenCache, key, accessToken);
        LOG.debug("Load AccessToken[{}] from DB and cache it, key = {}", accessToken, key);
    }

    return accessToken;
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro-redis,代码行数:17,代码来源:OAuthRSRedisRepository.java

示例11: findClientDetailsByClientIdAndResourceIds

import org.springframework.cache.Cache; //导入依赖的package包/类
@Override
public ClientDetails findClientDetailsByClientIdAndResourceIds(String clientId, String resourceIds) {

    final Cache clientDetailsCache = getClientDetailsCache();

    final String key = generateClientDetailsResourceIdsKey(clientId, resourceIds);
    ClientDetails clientDetails = (ClientDetails) getFromCache(clientDetailsCache, key);

    if (clientDetails == null) {
        clientDetails = oAuthRSRepository.findClientDetailsByClientIdAndResourceIds(clientId, resourceIds);
        putToCache(clientDetailsCache, key, clientDetails);
        LOG.debug("Load ClientDetails[{}] from DB and cache it, key = {}", clientDetails, key);
    }

    return clientDetails;
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro-redis,代码行数:17,代码来源:OAuthRSRedisRepository.java

示例12: saveAccessToken

import org.springframework.cache.Cache; //导入依赖的package包/类
@Override
public int saveAccessToken(AccessToken accessToken) {

    //add to cache
    final String key = generateAccessTokenKey(accessToken);
    final String key1 = generateAccessTokenUsernameClientIdAuthIdKey(accessToken);

    final Cache accessTokenCache = getAccessTokenCache();
    putToCache(accessTokenCache, key, accessToken);
    putToCache(accessTokenCache, key1, accessToken);
    LOG.debug("Cache AccessToken[{}], key = {}, key1 = {}", accessToken, key, key1);

    //refresh cache
    if (StringUtils.isNotEmpty(accessToken.refreshToken())) {
        final String key2 = generateAccessTokenRefreshKey(accessToken);
        putToCache(accessTokenCache, key2, accessToken);
        LOG.debug("Cache AccessToken[{}] by refresh-token, key = {}", accessToken, key2);
    }

    return oauthRepository.saveAccessToken(accessToken);
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro-redis,代码行数:22,代码来源:OauthRedisRepository.java

示例13: findOauthCode

import org.springframework.cache.Cache; //导入依赖的package包/类
@Override
public OauthCode findOauthCode(String code, String clientId) {

    final Cache oauthCodeCache = getOauthCodeCache();

    final String key = generateOauthCodeKey(code, clientId);
    OauthCode oauthCode = (OauthCode) getFromCache(oauthCodeCache, key);

    if (oauthCode == null) {
        oauthCode = oauthRepository.findOauthCode(code, clientId);
        putToCache(oauthCodeCache, key, oauthCode);
        LOG.debug("Load OauthCode[{}] from DB and cache it, code = {}, clientId = {}", oauthCode, code, clientId);
    }

    return oauthCode;
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro-redis,代码行数:17,代码来源:OauthRedisRepository.java

示例14: findAccessTokenByRefreshToken

import org.springframework.cache.Cache; //导入依赖的package包/类
@Override
public AccessToken findAccessTokenByRefreshToken(String refreshToken, String clientId) {

    final Cache accessTokenCache = getAccessTokenCache();

    final String key = generateAccessTokenRefreshKey(refreshToken, clientId);
    AccessToken accessToken = (AccessToken) getFromCache(accessTokenCache, key);

    if (accessToken == null) {
        accessToken = oauthRepository.findAccessTokenByRefreshToken(refreshToken, clientId);
        putToCache(accessTokenCache, key, accessToken);
        LOG.debug("Load AccessToken[{}] from DB and cache it, refreshToken = {}, clientId = {}", accessToken, refreshToken, clientId);
    }

    return accessToken;
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro-redis,代码行数:17,代码来源:OauthRedisRepository.java

示例15: doEvict

import org.springframework.cache.Cache; //导入依赖的package包/类
protected void doEvict(String cacheName, String key) {
    FluuzCache cache = cacheMap.get(cacheName);
    if (cache != null) {
        Cache proxy = cache.getProxy();
        proxy.evict(key);
        log.debug("evicted key '{}' from cache {}", key, cacheName);
    }
}
 
开发者ID:ArawakCC,项目名称:fluuz,代码行数:9,代码来源:RedisEventManager.java


注:本文中的org.springframework.cache.Cache类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。