本文整理汇总了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);
}
}
}
示例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);
}
示例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);
}
示例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));
}
示例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 ()));
}
}
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}