本文整理汇总了Java中org.springframework.cache.support.SimpleValueWrapper类的典型用法代码示例。如果您正苦于以下问题:Java SimpleValueWrapper类的具体用法?Java SimpleValueWrapper怎么用?Java SimpleValueWrapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleValueWrapper类属于org.springframework.cache.support包,在下文中一共展示了SimpleValueWrapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import org.springframework.cache.support.SimpleValueWrapper; //导入依赖的package包/类
@Override
public ValueWrapper get(Object key) {
checkNotNull(key, "null key is not allowed");
checkArgument(key instanceof Serializable, "key must implements Serializable");
Serializable sValue = codisTemplate.opsForValue().get(key);
if (Objects.nonNull(sValue)) {
if (log.isDebugEnabled()) {
log.debug("get object [{}] from cache by key [{}]", sValue, key);
}
return new SimpleValueWrapper(sValue);
} else {
if (log.isDebugEnabled()) {
log.debug("get object [{}] from cache by key [{}]", null, key);
}
return null;
}
}
示例2: getAndPutFail
import org.springframework.cache.support.SimpleValueWrapper; //导入依赖的package包/类
@Test
public void getAndPutFail() {
final UnsupportedOperationException exception = new UnsupportedOperationException(
"Test exception on get");
willThrow(exception).given(this.cache).get(0L);
willThrow(exception).given(this.cache).put(0L, 0L); // Update of the cache will
// fail as well
final Object counter = this.simpleService.get(0L);
willReturn(new SimpleValueWrapper(2L)).given(this.cache).get(0L);
final Object counter2 = this.simpleService.get(0L);
final Object counter3 = this.simpleService.get(0L);
assertThat(counter2).isEqualTo(counter3);
assertThat(counter).isNotEqualTo(counter2);
}
示例3: get
import org.springframework.cache.support.SimpleValueWrapper; //导入依赖的package包/类
@Override
public ValueWrapper get(final Object key) {
if (!cache.isEnabled()) {
LOGGER.warn("Cache {} is disabled. Cannot get {} from cache", cache.getName(), key);
return null;
}
Object value = getValue(key);
if (value == null) {
LOGGER.info("Cache miss. Get by key {} from cache {}", key, cache.getName());
return null;
}
LOGGER.info("Cache hit. Get by key {} from cache {} value '{}'", new Object[] { key, cache.getName(), value });
return value instanceof PertinentNegativeNull ? new SimpleValueWrapper(null) : new SimpleValueWrapper(value);
}
示例4: get
import org.springframework.cache.support.SimpleValueWrapper; //导入依赖的package包/类
@Override
public ValueWrapper get(Object key) {
Object value = null;
String cacheKey = null;
try {
cacheKey = createArcusKey(key);
logger.debug("getting value by key: {}", cacheKey);
Future<Object> future;
// operation transcoder can't be null.
if (operationTranscoder != null) {
future = arcusClient.asyncGet(cacheKey, operationTranscoder);
} else {
future = arcusClient.asyncGet(cacheKey);
}
value = future.get(timeoutMilliSeconds, TimeUnit.MILLISECONDS);
} catch (Exception e) {
logger.debug(e.getMessage());
if (wantToGetException) {
throw new RuntimeException(e);
}
}
return (value != null ? new SimpleValueWrapper(value) : null);
}
示例5: get
import org.springframework.cache.support.SimpleValueWrapper; //导入依赖的package包/类
@Override
public Object get(Object key) throws CacheException {
Object value = springCache.get(key);
if (value instanceof SimpleValueWrapper) {
return ((SimpleValueWrapper) value).get();
}
return value;
}
示例6: get
import org.springframework.cache.support.SimpleValueWrapper; //导入依赖的package包/类
@Override
public ValueWrapper get(Object key) {
Assert.notNull(key);
Object val = memcacheService.get(key);
if (val == null) {
return null;
}
if (val == NullValue.INSTANCE) {
val = null;
}
return new SimpleValueWrapper(val);
}
示例7: toValueWrapper
import org.springframework.cache.support.SimpleValueWrapper; //导入依赖的package包/类
private ValueWrapper toValueWrapper(Object value) {
if (value == null) {
return null;
}
if (value.getClass().getName().equals(NullValue.class.getName())) {
return NullValue.INSTANCE;
}
return new SimpleValueWrapper(value);
}
示例8: get
import org.springframework.cache.support.SimpleValueWrapper; //导入依赖的package包/类
@Override
public Object get(Object key) throws CacheException {
Object value = springCache.get(key);
if (value instanceof SimpleValueWrapper) {
return ((SimpleValueWrapper) value).get();
}
return value;
}
示例9: get
import org.springframework.cache.support.SimpleValueWrapper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public V get(K key) throws CacheException {
ValueWrapper value = cache.get(key);
if (value instanceof SimpleValueWrapper) {
return (V)((SimpleValueWrapper) value).get();
}
return (V)value;
}
示例10: putIfAbsent
import org.springframework.cache.support.SimpleValueWrapper; //导入依赖的package包/类
@Override
public ValueWrapper putIfAbsent(Object key, Object value) {
if (value == null) {
return new SimpleValueWrapper(null);
}
Object object = lookup(key);
if (object != null) {
return new SimpleValueWrapper(object);
}
put(key, value);
return new SimpleValueWrapper(value);
}
示例11: putIfAbsent
import org.springframework.cache.support.SimpleValueWrapper; //导入依赖的package包/类
@Override
public ValueWrapper putIfAbsent(Object key, Object value) {
if (value == null) {
return new SimpleValueWrapper(null);
}
ValueWrapper wrapper = get(key);
if (wrapper != null) {
return wrapper;
}
put(key, value);
return new SimpleValueWrapper(value);
}
示例12: getAndPutFail
import org.springframework.cache.support.SimpleValueWrapper; //导入依赖的package包/类
@Test
public void getAndPutFail() {
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get");
willThrow(exception).given(cache).get(0L);
willThrow(exception).given(cache).put(0L, 0L); // Update of the cache will fail as well
Object counter = this.simpleService.get(0L);
willReturn(new SimpleValueWrapper(2L)).given(cache).get(0L);
Object counter2 = this.simpleService.get(0L);
Object counter3 = this.simpleService.get(0L);
assertNotSame(counter, counter2);
assertEquals(counter2, counter3);
}
示例13: get
import org.springframework.cache.support.SimpleValueWrapper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public ValueWrapper get(final Object key) {
return (ValueWrapper) redisTemplate.execute(new RedisCallback<ValueWrapper>() {
public ValueWrapper doInRedis(RedisConnection connection) throws DataAccessException {
waitForLock(connection);
byte[] bs = connection.get(computeKey(key));
Object value = redisTemplate.getValueSerializer() != null ? redisTemplate.getValueSerializer().deserialize(bs) : bs;
return (bs == null ? null : new SimpleValueWrapper(value));
}
}, true);
}
示例14: putIfAbsent
import org.springframework.cache.support.SimpleValueWrapper; //导入依赖的package包/类
@Override
public ValueWrapper putIfAbsent(Object key, Object value) {
checkNotNull(key, "null key is not allowed");
checkArgument(key instanceof Serializable, "key must implements Serializable");
checkNotNull(value, "null value is not allowed");
checkArgument(value instanceof Serializable, "value must implements Serializable");
Serializable existValue = get(key, Serializable.class);
if (Objects.isNull(existValue)) {
put(key, value);
return null;
} else {
return new SimpleValueWrapper(existValue);
}
}
示例15: get
import org.springframework.cache.support.SimpleValueWrapper; //导入依赖的package包/类
public Object get(Object key) throws CacheException {
Object value = springCache.get(key);
if (value instanceof SimpleValueWrapper) {
return ((SimpleValueWrapper) value).get();
}
return value;
}