Here are the examples of the java api org.springframework.cache.Cache.put() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
137 Examples
19
View Source File : SysLoginService.java
License : Apache License 2.0
Project Creator : yang-cruise
License : Apache License 2.0
Project Creator : yang-cruise
private void addBadCredentialsCountBySecurity(String key) {
Integer failCount = securityCache.get(key, Integer.clreplaced);
failCount = Objects.isNull(failCount) ? 1 : failCount + 1;
securityCache.put(key, failCount);
}
19
View Source File : CachedDAOImpl.java
License : GNU General Public License v2.0
Project Creator : taktik
License : GNU General Public License v2.0
Project Creator : taktik
public void putInCache(String key, T value) {
cache.put(getFullId(key), value);
}
19
View Source File : SafeCache.java
License : GNU General Public License v2.0
Project Creator : taktik
License : GNU General Public License v2.0
Project Creator : taktik
public V get(K key, ValueProvider<K, V> valueProvider) {
V value;
Cache.ValueWrapper valueWrapper = cache.get(key);
if (valueWrapper == null) {
synchronized (this) {
valueWrapper = cache.get(key);
if (valueWrapper == null) {
value = valueProvider.getValue(key);
cache.put(key, value);
} else {
value = (V) valueWrapper.get();
}
}
} else {
value = (V) valueWrapper.get();
}
return value;
}
19
View Source File : SafeCache.java
License : GNU General Public License v2.0
Project Creator : taktik
License : GNU General Public License v2.0
Project Creator : taktik
public synchronized void put(K key, V value) {
cache.put(key, value);
}
19
View Source File : OAuth2Service.java
License : GNU General Public License v3.0
Project Creator : microacup
License : GNU General Public License v3.0
Project Creator : microacup
public void addCode(String code, String openId) {
codeCache.put(code, openId);
}
19
View Source File : OAuth2Service.java
License : GNU General Public License v3.0
Project Creator : microacup
License : GNU General Public License v3.0
Project Creator : microacup
public void addAccessToken(String accessToken, String openId) {
tokenCache.put(accessToken, openId);
}
19
View Source File : AuthServiceImpl.java
License : Apache License 2.0
Project Creator : gy2006
License : Apache License 2.0
Project Creator : gy2006
@Override
public Tokens login(String email, String preplacedwordOnMd5) {
User user = userService.getByEmail(email);
if (!Objects.equals(user.getPreplacedwordOnMd5(), preplacedwordOnMd5)) {
throw new ArgumentException("Invalid preplacedword");
}
// create token
String token = JwtHelper.create(user, authProperties.getExpireSeconds());
sessionManager.set(user);
onlineUsersCache.put(email, user);
// create refresh token
String refreshToken = HashingHelper.md5(email + preplacedwordOnMd5);
refreshTokenCache.put(email, refreshToken);
return new Tokens(token, refreshToken);
}
19
View Source File : TokenValidatorImpl.java
License : Apache License 2.0
Project Creator : codeabovelab
License : Apache License 2.0
Project Creator : codeabovelab
private void setLastAccess(TokenData tokenData, long currentTime) {
cache.put(tokenData.getKey(), currentTime);
}
19
View Source File : InMemoryClusterStore.java
License : Apache License 2.0
Project Creator : alibaba
License : Apache License 2.0
Project Creator : alibaba
@Override
public void addAgent(String agentId, AgentClusterInfo info, long timeout, TimeUnit timeUnit) {
cache.put(agentId, info);
}
18
View Source File : AbstractCacheAnnotationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
public void testMultiEvict(CacheableService<?> service) {
Object o1 = new Object();
Object o2 = o1.toString() + "A";
Object r1 = service.multiCache(o1);
Object r2 = service.multiCache(o1);
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
primary.put(o2, o2);
replacedertSame(r1, r2);
replacedertSame(r1, primary.get(o1).get());
replacedertSame(r1, secondary.get(o1).get());
service.multiEvict(o1);
replacedertNull(primary.get(o1));
replacedertNull(secondary.get(o1));
replacedertNull(primary.get(o2));
Object r3 = service.multiCache(o1);
Object r4 = service.multiCache(o1);
replacedertNotSame(r1, r3);
replacedertSame(r3, r4);
replacedertSame(r3, primary.get(o1).get());
replacedertSame(r4, secondary.get(o1).get());
}
18
View Source File : AbstractCacheAnnotationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
public void testMultiConditionalCacheAndEvict(CacheableService<?> service) {
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
Object key = 1;
secondary.put(key, key);
replacedertNull(primary.get(key));
replacedertSame(key, secondary.get(key).get());
Object r1 = service.multiConditionalCacheAndEvict(key);
Object r3 = service.multiConditionalCacheAndEvict(key);
replacedertTrue(!r1.equals(r3));
replacedertNull(primary.get(key));
Object key2 = 3;
Object r2 = service.multiConditionalCacheAndEvict(key2);
replacedertSame(r2, service.multiConditionalCacheAndEvict(key2));
// replacedert the method name is used
replacedertSame(r2, primary.get(key2).get());
replacedertNull(secondary.get(key2));
}
18
View Source File : AbstractCacheAnnotationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
public void testMultiCacheAndEvict(CacheableService<?> service) {
String methodName = "multiCacheAndEvict";
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
Object key = 1;
secondary.put(key, key);
replacedertNull(secondary.get(methodName));
replacedertSame(key, secondary.get(key).get());
Object r1 = service.multiCacheAndEvict(key);
replacedertSame(r1, service.multiCacheAndEvict(key));
// replacedert the method name is used
replacedertSame(r1, primary.get(methodName).get());
replacedertNull(secondary.get(methodName));
replacedertNull(secondary.get(key));
}
18
View Source File : AbstractCacheInvoker.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Execute {@link Cache#put(Object, Object)} on the specified {@link Cache}
* and invoke the error handler if an exception occurs.
*/
protected void doPut(Cache cache, Object key, @Nullable Object result) {
try {
cache.put(key, result);
} catch (RuntimeException ex) {
getErrorHandler().handleCachePutError(ex, cache, key, result);
}
}
18
View Source File : CachedDAOImpl.java
License : GNU General Public License v2.0
Project Creator : taktik
License : GNU General Public License v2.0
Project Creator : taktik
@Override
public List<T> getAll() {
Cache.ValueWrapper valueWrapper = cache.get(getFullId(ALL_ENreplacedIES_CACHE_KEY));
if (valueWrapper == null) {
List<T> allEnreplacedies = super.getAll();
cache.put(getFullId(ALL_ENreplacedIES_CACHE_KEY), allEnreplacedies);
return allEnreplacedies;
} else {
return (List<T>) valueWrapper.get();
}
}
18
View Source File : AbstractCacheAnnotationTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
protected void testMultiConditionalCacheAndEvict(CacheableService<?> service) {
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
Object key = 1;
secondary.put(key, key);
replacedertThat(primary.get(key)).isNull();
replacedertThat(secondary.get(key).get()).isSameAs(key);
Object r1 = service.multiConditionalCacheAndEvict(key);
Object r3 = service.multiConditionalCacheAndEvict(key);
replacedertThat(!r1.equals(r3)).isTrue();
replacedertThat(primary.get(key)).isNull();
Object key2 = 3;
Object r2 = service.multiConditionalCacheAndEvict(key2);
replacedertThat(service.multiConditionalCacheAndEvict(key2)).isSameAs(r2);
// replacedert the method name is used
replacedertThat(primary.get(key2).get()).isSameAs(r2);
replacedertThat(secondary.get(key2)).isNull();
}
18
View Source File : AbstractCacheAnnotationTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
protected void testMultiCacheAndEvict(CacheableService<?> service) {
String methodName = "multiCacheAndEvict";
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
Object key = 1;
secondary.put(key, key);
replacedertThat(secondary.get(methodName)).isNull();
replacedertThat(secondary.get(key).get()).isSameAs(key);
Object r1 = service.multiCacheAndEvict(key);
replacedertThat(service.multiCacheAndEvict(key)).isSameAs(r1);
// replacedert the method name is used
replacedertThat(primary.get(methodName).get()).isSameAs(r1);
replacedertThat(secondary.get(methodName)).isNull();
replacedertThat(secondary.get(key)).isNull();
}
18
View Source File : AbstractCacheAnnotationTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
protected void testMultiEvict(CacheableService<?> service) {
Object o1 = new Object();
Object o2 = o1.toString() + "A";
Object r1 = service.multiCache(o1);
Object r2 = service.multiCache(o1);
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
primary.put(o2, o2);
replacedertThat(r2).isSameAs(r1);
replacedertThat(primary.get(o1).get()).isSameAs(r1);
replacedertThat(secondary.get(o1).get()).isSameAs(r1);
service.multiEvict(o1);
replacedertThat(primary.get(o1)).isNull();
replacedertThat(secondary.get(o1)).isNull();
replacedertThat(primary.get(o2)).isNull();
Object r3 = service.multiCache(o1);
Object r4 = service.multiCache(o1);
replacedertThat(r3).isNotSameAs(r1);
replacedertThat(r4).isSameAs(r3);
replacedertThat(primary.get(o1).get()).isSameAs(r3);
replacedertThat(secondary.get(o1).get()).isSameAs(r4);
}
18
View Source File : TokenBrokerResolver.java
License : Apache License 2.0
Project Creator : SAP
License : Apache License 2.0
Project Creator : SAP
private String getBrokerToken(AuthenticationMethod credentialType, String authHeaderValue, String oauthTokenUrl, ClientCredentials clientCredentials) throws TokenBrokerException {
switch(credentialType) {
case OAUTH2:
String oAuth2token = extractAuthenticationFromHeader(AUTH_BEARER, authHeaderValue);
if (oAuth2token == null) {
break;
}
if (TokenUtil.isIasToXsuaaXchangeEnabled()) {
DecodedJwt decodedJwt = TokenUtil.decodeJwt(oAuth2token);
if (!TokenUtil.isXsuaaToken(decodedJwt)) {
try {
return iasXsuaaExchangeBroker.doIasXsuaaXchange(decodedJwt);
} catch (JSONException e) {
logger.error("Couldn't decode the token: {}", e.getMessage());
}
}
}
return oAuth2token;
case BASIC:
String basicAuthHeader = extractAuthenticationFromHeader(AUTH_BASIC_CREDENTIAL, authHeaderValue);
ClientCredentials userCredentialsFromHeader = getCredentialsFromBasicAuthorizationHeader(basicAuthHeader);
if (userCredentialsFromHeader != null) {
String cacheKey = createSecureHash(oauthTokenUrl, clientCredentials.toString(), userCredentialsFromHeader.toString());
String cachedToken = tokenCache.get(cacheKey, String.clreplaced);
if (cachedToken != null) {
logger.debug("return (basic) access token for {} from cache", cacheKey);
return cachedToken;
} else {
String token = tokenBroker.getAccessTokenFromPreplacedwordCredentials(oauthTokenUrl, clientCredentials.getId(), clientCredentials.getSecret(), userCredentialsFromHeader.getId(), userCredentialsFromHeader.getSecret());
tokenCache.put(cacheKey, token);
return token;
}
}
break;
case CLIENT_CREDENTIALS:
String clientCredentialsAuthHeader = extractAuthenticationFromHeader(AUTH_BASIC_CREDENTIAL, authHeaderValue);
ClientCredentials clientCredentialsFromHeader = getCredentialsFromBasicAuthorizationHeader(clientCredentialsAuthHeader);
if (clientCredentialsFromHeader != null) {
String cacheKey = createSecureHash(oauthTokenUrl, clientCredentialsFromHeader.toString());
String cachedToken = tokenCache.get(cacheKey, String.clreplaced);
if (cachedToken != null) {
logger.debug("return (client-credentials) access token for {} from cache", cacheKey);
return cachedToken;
} else {
String token = tokenBroker.getAccessTokenFromClientCredentials(oauthTokenUrl, clientCredentialsFromHeader.getId(), clientCredentialsFromHeader.getSecret());
tokenCache.put(cacheKey, token);
return token;
}
}
break;
default:
return null;
}
return null;
}
18
View Source File : CloudUserDetailsServiceImpl.java
License : GNU Lesser General Public License v3.0
Project Creator : renzl321
License : GNU Lesser General Public License v3.0
Project Creator : renzl321
/**
* 用户密码登录
*
* @param username 用户名
* @return
* @throws UsernameNotFoundException
*/
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
Cache cache = cacheManager.getCache("user_details");
if (cache != null && cache.get(username) != null) {
return (CloudUser) cache.get(username).get();
}
SmakerResult<UserInfo> result = remoteUserService.info(username, SecurityConstants.FROM_IN);
UserDetails userDetails = getUserDetails(result);
cache.put(username, userDetails);
return userDetails;
}
18
View Source File : BlackUserDetailsServiceImpl.java
License : Apache License 2.0
Project Creator : lizibin
License : Apache License 2.0
Project Creator : lizibin
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS);
if (cache != null && cache.get(username) != null) {
return (SecurityUserDetail) cache.get(username).get();
}
ResponseResult<UserInfoDTO> userOutDto = sysUserServiceClient.info(username);
UserDetails userDetails = buildUserDails(userOutDto);
cache.put(username, userDetails);
return userDetails;
}
18
View Source File : SpringCacheCaptchaCache.java
License : GNU Lesser General Public License v3.0
Project Creator : lets-mica
License : GNU Lesser General Public License v3.0
Project Creator : lets-mica
@Override
public void put(String cacheName, String uuid, String value) {
captchaCache.put(uuid, value);
}
18
View Source File : AbstractCacheAnnotationTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
public void testMultiEvict(CacheableService<?> service) {
Object o1 = new Object();
Object o2 = o1.toString() + "A";
Object r1 = service.multiCache(o1);
Object r2 = service.multiCache(o1);
Cache primary = cm.getCache("primary");
Cache secondary = cm.getCache("secondary");
primary.put(o2, o2);
replacedertSame(r1, r2);
replacedertSame(r1, primary.get(o1).get());
replacedertSame(r1, secondary.get(o1).get());
service.multiEvict(o1);
replacedertNull(primary.get(o1));
replacedertNull(secondary.get(o1));
replacedertNull(primary.get(o2));
Object r3 = service.multiCache(o1);
Object r4 = service.multiCache(o1);
replacedertNotSame(r1, r3);
replacedertSame(r3, r4);
replacedertSame(r3, primary.get(o1).get());
replacedertSame(r4, secondary.get(o1).get());
}
18
View Source File : AbstractCacheAnnotationTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
public void testMultiConditionalCacheAndEvict(CacheableService<?> service) {
Cache primary = cm.getCache("primary");
Cache secondary = cm.getCache("secondary");
Object key = Integer.valueOf(1);
secondary.put(key, key);
replacedertNull(primary.get(key));
replacedertSame(key, secondary.get(key).get());
Object r1 = service.multiConditionalCacheAndEvict(key);
Object r3 = service.multiConditionalCacheAndEvict(key);
replacedertTrue(!r1.equals(r3));
replacedertNull(primary.get(key));
Object key2 = Integer.valueOf(3);
Object r2 = service.multiConditionalCacheAndEvict(key2);
replacedertSame(r2, service.multiConditionalCacheAndEvict(key2));
// replacedert the method name is used
replacedertSame(r2, primary.get(key2).get());
replacedertNull(secondary.get(key2));
}
18
View Source File : AbstractCacheAnnotationTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
public void testMultiCacheAndEvict(CacheableService<?> service) {
String methodName = "multiCacheAndEvict";
Cache primary = cm.getCache("primary");
Cache secondary = cm.getCache("secondary");
Object key = Integer.valueOf(1);
secondary.put(key, key);
replacedertNull(secondary.get(methodName));
replacedertSame(key, secondary.get(key).get());
Object r1 = service.multiCacheAndEvict(key);
replacedertSame(r1, service.multiCacheAndEvict(key));
// replacedert the method name is used
replacedertSame(r1, primary.get(methodName).get());
replacedertNull(secondary.get(methodName));
replacedertNull(secondary.get(key));
}
18
View Source File : ConcurrentCacheTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
@Test
public void testCacheRemove() throws Exception {
Object key = "enescu";
Object value = "george";
replacedertNull(cache.get(key));
cache.put(key, value);
}
18
View Source File : ConcurrentCacheTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
@Test
public void testCachePut() throws Exception {
Object key = "enescu";
Object value = "george";
replacedertNull(cache.get(key));
replacedertNull(cache.get(key, String.clreplaced));
replacedertNull(cache.get(key, Object.clreplaced));
cache.put(key, value);
replacedertEquals(value, cache.get(key).get());
replacedertEquals(value, cache.get(key, String.clreplaced));
replacedertEquals(value, cache.get(key, Object.clreplaced));
replacedertEquals(value, cache.get(key, null));
cache.put(key, null);
replacedertNotNull(cache.get(key));
replacedertNull(cache.get(key).get());
replacedertNull(cache.get(key, String.clreplaced));
replacedertNull(cache.get(key, Object.clreplaced));
}
18
View Source File : AbstractCacheInvoker.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
/**
* Execute {@link Cache#put(Object, Object)} on the specified {@link Cache}
* and invoke the error handler if an exception occurs.
*/
protected void doPut(Cache cache, Object key, Object result) {
try {
cache.put(key, result);
} catch (RuntimeException e) {
getErrorHandler().handleCachePutError(e, cache, key, result);
}
}
18
View Source File : TwoLevelCacheTemplate.java
License : Apache License 2.0
Project Creator : i-novus-llc
License : Apache License 2.0
Project Creator : i-novus-llc
protected F handleFirstCache(K key, TwoLevelCacheCallback<F, S> callback, Cache firstLevelCache, S secondLevelCacheValue) {
F firstLevelCacheValue = callback.doInFirstLevelCacheMiss(secondLevelCacheValue);
if (firstLevelCache != null) {
firstLevelCache.put(key, firstLevelCacheValue);
}
return firstLevelCacheValue;
}
18
View Source File : TwoLevelCacheTemplate.java
License : Apache License 2.0
Project Creator : i-novus-llc
License : Apache License 2.0
Project Creator : i-novus-llc
protected S handleSecondCache(K key, TwoLevelCacheCallback<F, S> callback, Cache secondLevelCache) {
S secondLevelCacheValue = callback.doInSecondLevelCacheMiss();
if (secondLevelCache != null) {
secondLevelCache.put(key, secondLevelCacheValue);
}
return secondLevelCacheValue;
}
18
View Source File : ThreeLevelCacheTemplate.java
License : Apache License 2.0
Project Creator : i-novus-llc
License : Apache License 2.0
Project Creator : i-novus-llc
protected F handleSecondCache(Object firstKey, Object secondKey, ThreeLevelCacheCallback<F, S, T> callback, Cache firstLevelCache, Cache secondLevelCache, T thirdLevelCacheValue) {
S secondLevelCacheValue = callback.doInSecondLevelCacheMiss(thirdLevelCacheValue);
if (secondLevelCacheValue != null) {
secondLevelCache.put(secondKey, secondLevelCacheValue);
return handleFirstCache(firstKey, secondLevelCacheValue, firstLevelCache, callback);
}
return null;
}
18
View Source File : ThreeLevelCacheTemplate.java
License : Apache License 2.0
Project Creator : i-novus-llc
License : Apache License 2.0
Project Creator : i-novus-llc
protected F handleFirstCache(Object firstKey, S secondLevelCacheValue, Cache firstLevelCache, ThreeLevelCacheCallback<F, S, T> callback) {
F firstLevelCacheValue = callback.doInFirstLevelCacheMiss(secondLevelCacheValue);
if (firstLevelCache != null) {
firstLevelCache.put(firstKey, firstLevelCacheValue);
}
return firstLevelCacheValue;
}
18
View Source File : ThreeLevelCacheTemplate.java
License : Apache License 2.0
Project Creator : i-novus-llc
License : Apache License 2.0
Project Creator : i-novus-llc
protected F handleThirdCache(Object firstKey, Object secondKey, Object thirdKey, ThreeLevelCacheCallback<F, S, T> callback, Cache firstLevelCache, Cache secondLevelCache, Cache thirdLevelCache) {
T thirdLevelCacheValue = callback.doInThirdLevelCacheMiss();
if (thirdLevelCacheValue != null) {
thirdLevelCache.put(thirdKey, thirdLevelCacheValue);
F result = handleSecondCache(firstKey, secondKey, callback, firstLevelCache, secondLevelCache, thirdLevelCacheValue);
if (result != null)
return result;
}
return null;
}
18
View Source File : CacheTemplate.java
License : Apache License 2.0
Project Creator : i-novus-llc
License : Apache License 2.0
Project Creator : i-novus-llc
protected E handleCache(K key, CacheCallback<E> callback, Cache cache) {
E value = callback.doInCacheMiss();
cache.put(key, value);
return value;
}
18
View Source File : LockManagerImpl.java
License : Apache License 2.0
Project Creator : Haulmont
License : Apache License 2.0
Project Creator : Haulmont
@Override
public LockInfo lock(String name, String id) {
LockKey key = new LockKey(name, id);
LockInfo lockInfo = locks.get(key, LockInfo.clreplaced);
if (lockInfo != null) {
log.debug("Already locked: {}", lockInfo);
return lockInfo;
}
LockDescriptor ld = getConfig().get(name);
if (ld == null) {
return new LockNotSupported();
}
UserDetails user = currentAuthentication.getUser();
lockInfo = new LockInfo(user.getUsername(), name, id, timeSource.currentTimestamp());
locks.put(key, lockInfo);
log.debug("Locked {}/{}", name, id);
return null;
}
18
View Source File : ShiroSpringCache.java
License : Apache License 2.0
Project Creator : freezek
License : Apache License 2.0
Project Creator : freezek
@Override
public V put(K key, V value) throws CacheException {
if (logger.isTraceEnabled()) {
logger.trace("Putting object in cache [" + this.cache.getName() + "] for key [" + key + "]key type:" + key.getClreplaced());
}
V previous = get(key);
cache.put(key, value);
return previous;
}
18
View Source File : PaymentService.java
License : Apache License 2.0
Project Creator : fenixsoft
License : Apache License 2.0
Project Creator : fenixsoft
/**
* 生成支付单
* <p>
* 根据结算单冻结指定的货物,计算总价,生成支付单
*/
public Payment producePayment(Settlement bill) {
Double total = bill.gereplacedems().stream().mapToDouble(i -> {
stockpileService.frozen(i.getProductId(), i.getAmount());
return bill.productMap.get(i.getProductId()).getPrice() * i.getAmount();
}).sum() + // 12元固定运费,客户端写死的,这里陪着演一下,避免总价对不上
12;
Payment payment = new Payment(total, DEFAULT_PRODUCT_FROZEN_EXPIRES);
paymentRepository.save(payment);
// 将支付单存入缓存
settlementCache.put(payment.getPayId(), bill);
log.info("创建支付订单,总额:{}", payment.getTotalPrice());
return payment;
}
18
View Source File : ShiroSpringCache.java
License : Apache License 2.0
Project Creator : fengbindev
License : Apache License 2.0
Project Creator : fengbindev
@Override
public V put(K key, V value) throws CacheException {
cache.put(key, value);
return get(key);
}
18
View Source File : AbstractCacheSupport.java
License : MIT License
Project Creator : cwenao
License : MIT License
Project Creator : cwenao
/**
* 设置缓存数据
* @param cache
* @param key
* @param value
* @return
*/
protected boolean putCache(Cache cache, String key, Object value) {
if (null == value) {
return false;
}
cache.put(key, value);
return true;
}
18
View Source File : MultiL2Cache.java
License : Apache License 2.0
Project Creator : choerodon
License : Apache License 2.0
Project Creator : choerodon
@Override
public void put(Object key, Object value) {
l2Cache.put(key, value);
}
18
View Source File : MultiL1Cache.java
License : Apache License 2.0
Project Creator : choerodon
License : Apache License 2.0
Project Creator : choerodon
@Override
public void put(Object key, Object value) {
l1Cache.put(key, value);
}
18
View Source File : MultiAllCache.java
License : Apache License 2.0
Project Creator : choerodon
License : Apache License 2.0
Project Creator : choerodon
@Override
public void put(Object key, Object value) {
l1Cache.put(key, value);
l2Cache.put(key, value);
}
18
View Source File : CacheBeanDefinitionParserTest.java
License : Apache License 2.0
Project Creator : awspring
License : Apache License 2.0
Project Creator : awspring
@Test
void parseInternal_clusterCacheConfigurationWithCustomElastiCacheClient_returnsConfigurationWithCustomClient() throws Exception {
// Arrange
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
// Load xml file
XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);
xmlBeanDefinitionReader.loadBeanDefinitions(new ClreplacedPathResource(getClreplaced().getSimpleName() + "-elastiCacheConfigWithCustomElastiCacheClient.xml", getClreplaced()));
AmazonElastiCache amazonElastiCacheMock = beanFactory.getBean("customClient", AmazonElastiCache.clreplaced);
DescribeCacheClustersRequest memcached = new DescribeCacheClustersRequest().withCacheClusterId("memcached");
memcached.setShowCacheNodeInfo(true);
when(amazonElastiCacheMock.describeCacheClusters(memcached)).thenReturn(new DescribeCacheClustersResult().withCacheClusters(new CacheCluster().withCacheClusterId("memcached").withConfigurationEndpoint(new Endpoint().withAddress("localhost").withPort(Integer.parseInt(System.getProperty("memcachedPort")))).withCacheClusterStatus("available").withEngine("memcached")));
// Act
CacheManager cacheManager = beanFactory.getBean(CacheManager.clreplaced);
Cache cache = cacheManager.getCache("memcached");
cache.put("foo", "bar");
cache.evict("foo");
// replacedert
replacedertThat(cacheManager).isNotNull();
replacedertThat(cache).isNotNull();
}
18
View Source File : CacheBeanDefinitionParserTest.java
License : Apache License 2.0
Project Creator : awspring
License : Apache License 2.0
Project Creator : awspring
@Test
void parseInternal_customCache_returnsCacheManagerWithCustomCache() throws Exception {
// Arrange
ClreplacedPathXmlApplicationContext applicationContext = new ClreplacedPathXmlApplicationContext(getClreplaced().getSimpleName() + "-customCache.xml", getClreplaced());
// Act
CacheManager cacheManager = applicationContext.getBean(CacheManager.clreplaced);
Cache cache = cacheManager.getCache("memc");
cache.put("foo", "bar");
cache.evict("foo");
// replacedert
replacedertThat(cacheManager).isNotNull();
replacedertThat(cache).isNotNull();
}
17
View Source File : CacheManagerUtil.java
License : GNU Affero General Public License v3.0
Project Creator : zycSummer
License : GNU Affero General Public License v3.0
Project Creator : zycSummer
public void putCache(String cacheName, String key, Object value) {
Cache cache = cacheManager.getCache(cacheName);
if (cache != null) {
cache.put(key, value);
}
}
17
View Source File : SysLoginService.java
License : Apache License 2.0
Project Creator : yang-cruise
License : Apache License 2.0
Project Creator : yang-cruise
private String getPreplacedwordErrorMsg(LoginPrincipal principal) {
Integer failCount = accountCache.get(principal.getPrincipal(), Integer.clreplaced);
failCount = Objects.isNull(failCount) ? 1 : failCount + 1;
accountCache.put(principal.getPrincipal(), failCount);
int lockAccountCount = getLockAccountCount();
int surplusCount = lockAccountCount - failCount;
return surplusCount > 0 ? String.format("密码错误,还剩%s次机会", surplusCount) : String.format("密码错误%s次,锁定10分钟", lockAccountCount);
}
17
View Source File : SysLoginController.java
License : Apache License 2.0
Project Creator : yang-cruise
License : Apache License 2.0
Project Creator : yang-cruise
@ApiOperation(value = "获取验证码")
@GetMapping("/captcha")
public CaptchaVO getCaptcha() {
CaptchaVO captchaVO = new CaptchaVO().setShow(Boolean.FALSE);
String securityVerifyCacheKey = sysLoginService.getSecurityVerifyCacheKey();
Integer failCount = securityCache.get(securityVerifyCacheKey, Integer.clreplaced);
AccountConfigVO accountLoginConfig = sysConfigService.getAccountLoginConfig();
if (Objects.nonNull(failCount) && failCount >= accountLoginConfig.getShowCaptchaCount()) {
captchaVO.setShow(Boolean.TRUE);
ArithmeticCaptcha specCaptcha = new ArithmeticCaptcha(100, 32, 2);
String captcha = specCaptcha.text().toLowerCase();
String uuid = UUID.randomUUID().toString();
captchaCache.put(uuid, captcha);
captchaVO.setUuid(uuid).setImage(specCaptcha.toBase64());
}
return captchaVO;
}
17
View Source File : TransactionAwareCacheDecoratorTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void evictTransactional() {
Cache target = new ConcurrentMapCache("testCache");
Cache cache = new TransactionAwareCacheDecorator(target);
Object key = new Object();
cache.put(key, "123");
TransactionStatus status = this.txManager.getTransaction(new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED));
cache.evict(key);
replacedertEquals("123", target.get(key, String.clreplaced));
this.txManager.commit(status);
replacedertNull(target.get(key));
}
17
View Source File : TransactionAwareCacheDecoratorTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void evictNonTransactional() {
Cache target = new ConcurrentMapCache("testCache");
Cache cache = new TransactionAwareCacheDecorator(target);
Object key = new Object();
cache.put(key, "123");
cache.evict(key);
replacedertNull(target.get(key));
}
17
View Source File : TransactionAwareCacheDecoratorTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void putTransactional() {
Cache target = new ConcurrentMapCache("testCache");
Cache cache = new TransactionAwareCacheDecorator(target);
TransactionStatus status = this.txManager.getTransaction(new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED));
Object key = new Object();
cache.put(key, "123");
replacedertNull(target.get(key));
this.txManager.commit(status);
replacedertEquals("123", target.get(key, String.clreplaced));
}
17
View Source File : TransactionAwareCacheDecoratorTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void putNonTransactional() {
Cache target = new ConcurrentMapCache("testCache");
Cache cache = new TransactionAwareCacheDecorator(target);
Object key = new Object();
cache.put(key, "123");
replacedertEquals("123", target.get(key, String.clreplaced));
}
See More Examples