Here are the examples of the java api org.springframework.cache.Cache.get() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
243 Examples
19
View Source File : AnnotatedJCacheableService.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Override
@CachePut(afterInvocation = false)
public void earlyPut(String id, @CacheValue Object value) {
Object key = SimpleKeyGenerator.generateKey(id);
Cache.ValueWrapper valueWrapper = defaultCache.get(key);
if (valueWrapper == null) {
throw new replacedertionError("Excepted value to be put in cache with key " + key);
}
Object actual = valueWrapper.get();
if (value != actual) {
// instance check on purpose
throw new replacedertionError("Wrong value set in cache with key " + key + ". " + "Expected=" + value + ", but got=" + actual);
}
}
19
View Source File : AnnotatedJCacheableService.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Override
@CacheRemove(afterInvocation = false)
public void earlyRemove(String id) {
Object key = SimpleKeyGenerator.generateKey(id);
Cache.ValueWrapper valueWrapper = defaultCache.get(key);
if (valueWrapper != null) {
throw new replacedertionError("Value with key " + key + " expected to be already remove from cache");
}
}
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 T getFromCache(String id) {
Cache.ValueWrapper value = cache.get(getFullId(id));
return value == null ? null : (T) value.get();
}
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
protected Cache.ValueWrapper getWrapperFromCache(String id) {
return cache.get(getFullId(id));
}
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 getIfPresent(K key) {
Cache.ValueWrapper valueWrapper = cache.get(key);
return (valueWrapper != null) ? (V) valueWrapper.get() : null;
}
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 String getOpenId(String code) {
Cache.ValueWrapper valueWrapper = codeCache.get(code);
if (valueWrapper == null)
return null;
return (String) valueWrapper.get();
}
19
View Source File : LockManagerImpl.java
License : Apache License 2.0
Project Creator : Haulmont
License : Apache License 2.0
Project Creator : Haulmont
@Override
public LockInfo getLockInfo(String name, String id) {
LockDescriptor ld = getConfig().get(name);
if (ld == null) {
return new LockNotSupported();
}
return locks.get(new LockKey(name, id), LockInfo.clreplaced);
}
19
View Source File : TokenValidatorImpl.java
License : Apache License 2.0
Project Creator : codeabovelab
License : Apache License 2.0
Project Creator : codeabovelab
private Long getLastAccess(TokenData tokenData) {
Cache.ValueWrapper wrapper = cache.get(tokenData.getKey());
return wrapper == null ? null : (Long) wrapper.get();
}
19
View Source File : InMemoryClusterStore.java
License : Apache License 2.0
Project Creator : alibaba
License : Apache License 2.0
Project Creator : alibaba
@Override
public AgentClusterInfo findAgent(String agentId) {
ValueWrapper valueWrapper = cache.get(agentId);
if (valueWrapper == null) {
return null;
}
AgentClusterInfo info = (AgentClusterInfo) valueWrapper.get();
return info;
}
18
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);
}
18
View Source File : JCacheKeyGeneratorTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void getFiltered() {
this.keyGenerator.expect(1L);
Object first = this.simpleService.getFiltered(1L, "foo", "bar");
Object second = this.simpleService.getFiltered(1L, "foo", "bar");
replacedertSame(first, second);
Object key = new SimpleKey(1L);
replacedertEquals(first, cache.get(key).get());
}
18
View Source File : JCacheKeyGeneratorTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void getSimple() {
this.keyGenerator.expect(1L);
Object first = this.simpleService.get(1L);
Object second = this.simpleService.get(1L);
replacedertSame(first, second);
Object key = new SimpleKey(1L);
replacedertEquals(first, cache.get(key).get());
}
18
View Source File : JCacheKeyGeneratorTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void getFlattenVararg() {
this.keyGenerator.expect(1L, "foo", "bar");
Object first = this.simpleService.get(1L, "foo", "bar");
Object second = this.simpleService.get(1L, "foo", "bar");
replacedertSame(first, second);
Object key = new SimpleKey(1L, "foo", "bar");
replacedertEquals(first, cache.get(key).get());
}
18
View Source File : AbstractCacheAnnotationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
public void testMultiPut(CacheableService<?> service) {
Object o = 1;
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
replacedertNull(primary.get(o));
replacedertNull(secondary.get(o));
Object r1 = service.multiUpdate(o);
replacedertSame(r1, primary.get(o).get());
replacedertSame(r1, secondary.get(o).get());
o = 2;
replacedertNull(primary.get(o));
replacedertNull(secondary.get(o));
Object r2 = service.multiUpdate(o);
replacedertSame(r2, primary.get(o).get());
replacedertSame(r2, secondary.get(o).get());
}
18
View Source File : AbstractCacheAnnotationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
public void testPutRefersToResult(CacheableService<?> service) throws Exception {
Long id = Long.MIN_VALUE;
TestEnreplacedy enreplacedy = new TestEnreplacedy();
Cache primary = this.cm.getCache("primary");
replacedertNull(primary.get(id));
replacedertNull(enreplacedy.getId());
service.putRefersToResult(enreplacedy);
replacedertSame(enreplacedy, primary.get(id).get());
}
18
View Source File : AbstractCacheAnnotationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
public void testCacheUpdate(CacheableService<?> service) {
Object o = new Object();
Cache cache = this.cm.getCache("testCache");
replacedertNull(cache.get(o));
Object r1 = service.update(o);
replacedertSame(r1, cache.get(o).get());
o = new Object();
replacedertNull(cache.get(o));
Object r2 = service.update(o);
replacedertSame(r2, cache.get(o).get());
}
18
View Source File : AbstractCacheAnnotationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
public void testMultiCache(CacheableService<?> service) {
Object o1 = new Object();
Object o2 = new Object();
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
replacedertNull(primary.get(o1));
replacedertNull(secondary.get(o1));
Object r1 = service.multiCache(o1);
replacedertSame(r1, primary.get(o1).get());
replacedertSame(r1, secondary.get(o1).get());
Object r2 = service.multiCache(o1);
Object r3 = service.multiCache(o1);
replacedertSame(r1, r2);
replacedertSame(r1, r3);
replacedertNull(primary.get(o2));
replacedertNull(secondary.get(o2));
Object r4 = service.multiCache(o2);
replacedertSame(r4, primary.get(o2).get());
replacedertSame(r4, secondary.get(o2).get());
}
18
View Source File : AbstractCacheAnnotationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
public void testEvictAll(CacheableService<?> service) throws Exception {
Object o1 = new Object();
Object r1 = service.cache(o1);
Object r2 = service.cache(o1);
Object o2 = new Object();
Object r10 = service.cache(o2);
replacedertSame(r1, r2);
replacedertNotSame(r1, r10);
service.evictAll(new Object());
Cache cache = this.cm.getCache("testCache");
replacedertNull(cache.get(o1));
replacedertNull(cache.get(o2));
Object r3 = service.cache(o1);
Object r4 = service.cache(o1);
replacedertNotSame(r1, r3);
replacedertSame(r3, r4);
}
18
View Source File : AbstractCacheAnnotationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
public void testConditionalCacheUpdate(CacheableService<?> service) {
Integer one = 1;
Integer three = 3;
Cache cache = this.cm.getCache("testCache");
replacedertEquals(one, Integer.valueOf(service.conditionalUpdate(one).toString()));
replacedertNull(cache.get(one));
replacedertEquals(three, Integer.valueOf(service.conditionalUpdate(three).toString()));
replacedertEquals(three, Integer.valueOf(cache.get(three).get().toString()));
}
18
View Source File : AbstractCacheAnnotationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
public void testRootVars(CacheableService<?> service) {
Object key = new Object();
Object r1 = service.rootVars(key);
replacedertSame(r1, service.rootVars(key));
Cache cache = this.cm.getCache("testCache");
// replacedert the method name is used
String expectedKey = "rootVarsrootVars" + AopProxyUtils.ultimateTargetClreplaced(service) + service;
replacedertNotNull(cache.get(expectedKey));
}
18
View Source File : AbstractCacheAnnotationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
public void testMethodName(CacheableService<?> service, String keyName) throws Exception {
Object key = new Object();
Object r1 = service.name(key);
replacedertSame(r1, service.name(key));
Cache cache = this.cm.getCache("testCache");
// replacedert the method name is used
replacedertNotNull(cache.get(keyName));
}
18
View Source File : CacheAspectSupport.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Nullable
private Object execute(final CacheOperationInvoker invoker, Method method, CacheOperationContexts contexts) {
// Special handling of synchronized invocation
if (contexts.isSynchronized()) {
CacheOperationContext context = contexts.get(CacheableOperation.clreplaced).iterator().next();
if (isConditionPreplaceding(context, CacheOperationExpressionEvaluator.NO_RESULT)) {
Object key = generateKey(context, CacheOperationExpressionEvaluator.NO_RESULT);
Cache cache = context.getCaches().iterator().next();
try {
return wrapCacheValue(method, cache.get(key, () -> unwrapReturnValue(invokeOperation(invoker))));
} catch (Cache.ValueRetrievalException ex) {
// The invoker wraps any Throwable in a ThrowableWrapper instance so we
// can just make sure that one bubbles up the stack.
throw (CacheOperationInvoker.ThrowableWrapper) ex.getCause();
}
} else {
// No caching required, only call the underlying method
return invokeOperation(invoker);
}
}
// Process any early evictions
processCacheEvicts(contexts.get(CacheEvictOperation.clreplaced), true, CacheOperationExpressionEvaluator.NO_RESULT);
// Check if we have a cached item matching the conditions
Cache.ValueWrapper cacheHit = findCachedItem(contexts.get(CacheableOperation.clreplaced));
// Collect puts from any @Cacheable miss, if no cached item is found
List<CachePutRequest> cachePutRequests = new LinkedList<>();
if (cacheHit == null) {
collectPutRequests(contexts.get(CacheableOperation.clreplaced), CacheOperationExpressionEvaluator.NO_RESULT, cachePutRequests);
}
Object cacheValue;
Object returnValue;
if (cacheHit != null && !hasCachePut(contexts)) {
// If there are no put requests, just use the cache hit
cacheValue = cacheHit.get();
returnValue = wrapCacheValue(method, cacheValue);
} else {
// Invoke the method if we don't have a cache hit
returnValue = invokeOperation(invoker);
cacheValue = unwrapReturnValue(returnValue);
}
// Collect any explicit @CachePuts
collectPutRequests(contexts.get(CachePutOperation.clreplaced), cacheValue, cachePutRequests);
// Process any collected put requests, either from @CachePut or a @Cacheable miss
for (CachePutRequest cachePutRequest : cachePutRequests) {
cachePutRequest.apply(cacheValue);
}
// Process any late evictions
processCacheEvicts(contexts.get(CacheEvictOperation.clreplaced), false, cacheValue);
return returnValue;
}
18
View Source File : AbstractCacheInvoker.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Execute {@link Cache#get(Object)} on the specified {@link Cache} and
* invoke the error handler if an exception occurs. Return {@code null}
* if the handler does not throw any exception, which simulates a cache
* miss in case of error.
* @see Cache#get(Object)
*/
@Nullable
protected Cache.ValueWrapper doGet(Cache cache, Object key) {
try {
return cache.get(key);
} catch (RuntimeException ex) {
getErrorHandler().handleCacheGetError(ex, cache, key);
// If the exception is handled, return a cache miss
return null;
}
}
18
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;
}
18
View Source File : JCacheKeyGeneratorTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void getSimple() {
this.keyGenerator.expect(1L);
Object first = this.simpleService.get(1L);
Object second = this.simpleService.get(1L);
replacedertThat(second).isSameAs(first);
Object key = new SimpleKey(1L);
replacedertThat(cache.get(key).get()).isEqualTo(first);
}
18
View Source File : JCacheKeyGeneratorTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void getFiltered() {
this.keyGenerator.expect(1L);
Object first = this.simpleService.getFiltered(1L, "foo", "bar");
Object second = this.simpleService.getFiltered(1L, "foo", "bar");
replacedertThat(second).isSameAs(first);
Object key = new SimpleKey(1L);
replacedertThat(cache.get(key).get()).isEqualTo(first);
}
18
View Source File : JCacheKeyGeneratorTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void getFlattenVararg() {
this.keyGenerator.expect(1L, "foo", "bar");
Object first = this.simpleService.get(1L, "foo", "bar");
Object second = this.simpleService.get(1L, "foo", "bar");
replacedertThat(second).isSameAs(first);
Object key = new SimpleKey(1L, "foo", "bar");
replacedertThat(cache.get(key).get()).isEqualTo(first);
}
18
View Source File : CacheTestUtils.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
/**
* replacedert the following key has a matching value within the specified cache(s).
*/
public static void replacedertCacheHit(Object key, Object value, Cache... caches) {
for (Cache cache : caches) {
Cache.ValueWrapper wrapper = cache.get(key);
replacedertThat(wrapper).as("An entry in " + cache + " should have been found with key " + key).isNotNull();
replacedertThat(wrapper.get()).as("Wrong value in " + cache + " for entry with key " + key).isEqualTo(value);
}
}
18
View Source File : CacheTestUtils.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
/**
* replacedert the following key is not held within the specified cache(s).
*/
public static void replacedertCacheMiss(Object key, Cache... caches) {
for (Cache cache : caches) {
replacedertThat(cache.get(key)).as("No entry in " + cache + " should have been found with key " + 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 testEvictAll(CacheableService<?> service, boolean successExpected) {
Cache cache = this.cm.getCache("testCache");
Object o1 = new Object();
Object o2 = new Object();
cache.putIfAbsent(o1, -1L);
cache.putIfAbsent(o2, -2L);
Object r1 = service.cache(o1);
Object r2 = service.cache(o2);
replacedertThat(r2).isNotSameAs(r1);
service.evictAll(new Object());
if (successExpected) {
replacedertThat(cache.get(o1)).isNull();
replacedertThat(cache.get(o2)).isNull();
} else {
replacedertThat(cache.get(o1)).isNotNull();
replacedertThat(cache.get(o2)).isNotNull();
}
Object r3 = service.cache(o1);
Object r4 = service.cache(o2);
if (successExpected) {
replacedertThat(r3).isNotSameAs(r1);
replacedertThat(r4).isNotSameAs(r2);
} else {
replacedertThat(r3).isSameAs(r1);
replacedertThat(r4).isSameAs(r2);
}
}
18
View Source File : AbstractCacheAnnotationTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
protected void testEvictEarly(CacheableService<?> service) {
Cache cache = this.cm.getCache("testCache");
Object o1 = new Object();
cache.putIfAbsent(o1, -1L);
Object r1 = service.cache(o1);
try {
service.evictEarly(o1);
} catch (RuntimeException ex) {
// expected
}
replacedertThat(cache.get(o1)).isNull();
Object r2 = service.cache(o1);
replacedertThat(r2).isNotSameAs(r1);
}
18
View Source File : AbstractCacheAnnotationTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void testCustomCacheManager() {
CacheManager customCm = this.ctx.getBean("customCacheManager", CacheManager.clreplaced);
Object key = new Object();
Object r1 = this.cs.customCacheManager(key);
replacedertThat(this.cs.customCacheManager(key)).isSameAs(r1);
Cache cache = customCm.getCache("testCache");
replacedertThat(cache.get(key)).isNotNull();
}
18
View Source File : AbstractCacheAnnotationTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void testCustomKeyGenerator() {
Object param = new Object();
Object r1 = this.cs.customKeyGenerator(param);
replacedertThat(this.cs.customKeyGenerator(param)).isSameAs(r1);
Cache cache = this.cm.getCache("testCache");
// Checks that the custom keyGenerator was used
Object expectedKey = SomeCustomKeyGenerator.generateKey("customKeyGenerator", param);
replacedertThat(cache.get(expectedKey)).isNotNull();
}
18
View Source File : AbstractCacheAnnotationTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
protected void testEvictAllEarly(CacheableService<?> service) {
Cache cache = this.cm.getCache("testCache");
Object o1 = new Object();
Object o2 = new Object();
cache.putIfAbsent(o1, -1L);
cache.putIfAbsent(o2, -2L);
Object r1 = service.cache(o1);
Object r2 = service.cache(o2);
replacedertThat(r2).isNotSameAs(r1);
try {
service.evictAllEarly(new Object());
} catch (Exception ex) {
// expected
}
replacedertThat(cache.get(o1)).isNull();
replacedertThat(cache.get(o2)).isNull();
Object r3 = service.cache(o1);
Object r4 = service.cache(o2);
replacedertThat(r3).isNotSameAs(r1);
replacedertThat(r4).isNotSameAs(r2);
}
18
View Source File : AbstractCacheAnnotationTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
protected void testCacheUpdate(CacheableService<?> service) {
Object o = new Object();
Cache cache = this.cm.getCache("testCache");
replacedertThat(cache.get(o)).isNull();
Object r1 = service.update(o);
replacedertThat(cache.get(o).get()).isSameAs(r1);
o = new Object();
replacedertThat(cache.get(o)).isNull();
Object r2 = service.update(o);
replacedertThat(cache.get(o).get()).isSameAs(r2);
}
18
View Source File : AbstractCacheAnnotationTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
protected void testRootVars(CacheableService<?> service) {
Object key = new Object();
Object r1 = service.rootVars(key);
replacedertThat(service.rootVars(key)).isSameAs(r1);
Cache cache = this.cm.getCache("testCache");
// replacedert the method name is used
String expectedKey = "rootVarsrootVars" + AopProxyUtils.ultimateTargetClreplaced(service) + service;
replacedertThat(cache.get(expectedKey)).isNotNull();
}
18
View Source File : AbstractCacheAnnotationTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
protected void testEvict(CacheableService<?> service, boolean successExpected) {
Cache cache = this.cm.getCache("testCache");
Object o1 = new Object();
cache.putIfAbsent(o1, -1L);
Object r1 = service.cache(o1);
service.evict(o1, null);
if (successExpected) {
replacedertThat(cache.get(o1)).isNull();
} else {
replacedertThat(cache.get(o1)).isNotNull();
}
Object r2 = service.cache(o1);
if (successExpected) {
replacedertThat(r2).isNotSameAs(r1);
} else {
replacedertThat(r2).isSameAs(r1);
}
}
18
View Source File : AbstractCacheAnnotationTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
protected void testMultiCache(CacheableService<?> service) {
Object o1 = new Object();
Object o2 = new Object();
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
replacedertThat(primary.get(o1)).isNull();
replacedertThat(secondary.get(o1)).isNull();
Object r1 = service.multiCache(o1);
replacedertThat(primary.get(o1).get()).isSameAs(r1);
replacedertThat(secondary.get(o1).get()).isSameAs(r1);
Object r2 = service.multiCache(o1);
Object r3 = service.multiCache(o1);
replacedertThat(r2).isSameAs(r1);
replacedertThat(r3).isSameAs(r1);
replacedertThat(primary.get(o2)).isNull();
replacedertThat(secondary.get(o2)).isNull();
Object r4 = service.multiCache(o2);
replacedertThat(primary.get(o2).get()).isSameAs(r4);
replacedertThat(secondary.get(o2).get()).isSameAs(r4);
}
18
View Source File : AbstractCacheAnnotationTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
protected void testMultiPut(CacheableService<?> service) {
Object o = 1;
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
replacedertThat(primary.get(o)).isNull();
replacedertThat(secondary.get(o)).isNull();
Object r1 = service.multiUpdate(o);
replacedertThat(primary.get(o).get()).isSameAs(r1);
replacedertThat(secondary.get(o).get()).isSameAs(r1);
o = 2;
replacedertThat(primary.get(o)).isNull();
replacedertThat(secondary.get(o)).isNull();
Object r2 = service.multiUpdate(o);
replacedertThat(primary.get(o).get()).isSameAs(r2);
replacedertThat(secondary.get(o).get()).isSameAs(r2);
}
18
View Source File : AbstractCacheAnnotationTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
protected void testMethodName(CacheableService<?> service, String keyName) {
Object key = new Object();
Object r1 = service.name(key);
replacedertThat(service.name(key)).isSameAs(r1);
Cache cache = this.cm.getCache("testCache");
// replacedert the method name is used
replacedertThat(cache.get(keyName)).isNotNull();
}
18
View Source File : AbstractCacheAnnotationTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
protected void testConditionalCacheUpdate(CacheableService<?> service) {
Integer one = 1;
Integer three = 3;
Cache cache = this.cm.getCache("testCache");
replacedertThat((int) Integer.valueOf(service.conditionalUpdate(one).toString())).isEqualTo((int) one);
replacedertThat(cache.get(one)).isNull();
replacedertThat((int) Integer.valueOf(service.conditionalUpdate(three).toString())).isEqualTo((int) three);
replacedertThat((int) Integer.valueOf(cache.get(three).get().toString())).isEqualTo((int) three);
}
18
View Source File : MemcachedCacheMeterBinderProviderConfigurationTest.java
License : Apache License 2.0
Project Creator : sixhours-team
License : Apache License 2.0
Project Creator : sixhours-team
private void getCacheKeyValues(Cache cache, String... keys) {
for (String key : keys) {
cache.get(key);
}
}
18
View Source File : TranslateCaffeineManager.java
License : Apache License 2.0
Project Creator : sagframe
License : Apache License 2.0
Project Creator : sagframe
@Override
public HashMap<String, Object[]> getCache(String cacheName, String cacheType) {
if (cacheManager == null) {
return null;
}
Cache cache = cacheManager.getCache(cacheName);
if (cache == null) {
return null;
}
Cache.ValueWrapper wrapper = cache.get(StringUtil.isNotBlank(cacheType) ? cacheType : cacheName);
if (wrapper != null) {
return (HashMap<String, Object[]>) wrapper.get();
}
return null;
}
18
View Source File : SEBClientConnectionServiceImpl.java
License : Mozilla Public License 2.0
Project Creator : SafeExamBrowser
License : Mozilla Public License 2.0
Project Creator : SafeExamBrowser
@Override
public void updatePingEvents() {
try {
final Cache cache = this.cacheManager.getCache(ExamSessionCacheService.CACHE_NAME_ACTIVE_CLIENT_CONNECTION);
this.examSessionService.getExamDAO().allRunningExamIds().getOrThrow().stream().flatMap(examId -> this.clientConnectionDAO.getConnectionTokens(examId).getOrThrow().stream()).map(token -> cache.get(token, ClientConnectionDataInternal.clreplaced)).filter(Objects::nonNull).filter(connection -> connection.pingIndicator != null && connection.clientConnection.status.establishedStatus).map(connection -> connection.pingIndicator.updateLogEvent()).filter(Objects::nonNull).forEach(this.eventHandlingStrategy);
} catch (final Exception e) {
log.error("Failed to update ping events: ", e);
}
}
18
View Source File : ExamSessionServiceImpl.java
License : Mozilla Public License 2.0
Project Creator : SafeExamBrowser
License : Mozilla Public License 2.0
Project Creator : SafeExamBrowser
@Override
public Result<ClientConnectionData> getConnectionData(final String connectionToken) {
return Result.tryCatch(() -> {
final Cache cache = this.cacheManager.getCache(ExamSessionCacheService.CACHE_NAME_ACTIVE_CLIENT_CONNECTION);
return cache.get(connectionToken, ClientConnectionData.clreplaced);
});
}
18
View Source File : GitHubTests.java
License : GNU General Public License v3.0
Project Creator : mintster
License : GNU General Public License v3.0
Project Creator : mintster
@Test
public void validateGithubStatsCache() throws Exception {
replacedertNotNull(githubCache);
GitHubStats gitHubStats = webUI.getCurrentGitHubStats();
githubCache.get("getCurrentGitHubStats");
replacedertThat(((GitHubStats) githubCache.get("getCurrentGitHubStats").get()).getFollowers(), greaterThan(-1));
}
18
View Source File : PostCachingTests.java
License : GNU General Public License v3.0
Project Creator : mintster
License : GNU General Public License v3.0
Project Creator : mintster
@Test
public void validateCacheByPostName() throws Exception {
replacedertThat(postCache.get("a-java-collection-of-value-pairs-tuples")).isNull();
Post post = postService.getPost("a-java-collection-of-value-pairs-tuples");
replacedertThat((Post) postCache.get(post.getPostName()).get()).isEqualTo(post);
}
18
View Source File : PostCachingTests.java
License : GNU General Public License v3.0
Project Creator : mintster
License : GNU General Public License v3.0
Project Creator : mintster
@Test
public void validateCacheByPostId() throws Exception {
replacedertThat(postCache.get(1L)).isNull();
Post post = postService.getPostById(1L);
replacedertThat((Post) postCache.get(post.getPostId()).get()).isEqualTo(post);
}
18
View Source File : DictClient.java
License : MIT License
Project Creator : leecho
License : MIT License
Project Creator : leecho
/**
* 通过数据字典代码获取数据字典值
* @param parent
* @return
*/
public Map<String, DictVO> getByParent(String parent) {
Cache cache = cacheManager.getCache(CacheConstants.DICT_ITEM_CACHE_NAME);
Cache.ValueWrapper valueWrapper = cache.get(parent);
if (valueWrapper != null) {
return (Map) valueWrapper.get();
}
return null;
}
18
View Source File : SysResourceCacheService.java
License : MIT License
Project Creator : leecho
License : MIT License
Project Creator : leecho
/**
* 根据角色获取资源立标
* @param role
* @return
*/
public Set<String> getResourceCodesByRole(String role) {
Cache cache = cacheManager.getCache(ResourceCacheConstant.ROLE_RESOURCE_MAPPING_CACHE);
if (cache != null) {
Cache.ValueWrapper value = cache.get(role);
if (value != null && value.get() != null) {
return (Set<String>) value.get();
}
}
return new HashSet<>();
}
See More Examples