List of usage examples for org.springframework.cache.support SimpleValueWrapper SimpleValueWrapper
public SimpleValueWrapper(@Nullable Object value)
From source file:org.redisson.spring.cache.RedissonCache.java
private ValueWrapper toValueWrapper(Object value) { if (value == null) { return null; }/*from www. j a v a 2s . c om*/ if (value.getClass().getName().equals(NullValue.class.getName())) { return NullValue.INSTANCE; } return new SimpleValueWrapper(value); }
From source file:us.swcraft.springframework.cache.aerospike.AerospikeCache.java
/** * {@inheritDoc}/*from ww w. jav a 2 s .c om*/ */ @SuppressWarnings("unchecked") @Override public ValueWrapper get(final Object key) { final String k = key.toString(); final Record record = template.fetch(k); if (record == null) { log.trace("Not found: {}", k); return null; } else { final String className = record.getString(CLASS_NAME_BIN); if ("NIL".equals(className)) { // null-value stored log.trace("Got: {}=null", k); template.touch(k); return new SimpleValueWrapper(null); } final byte[] binaryContent = (byte[]) record.getValue(VALUE_BIN); try { final Object value = serializer.deserialize(binaryContent, Class.forName(className)); log.trace("Got: {}={}", key, value); template.touch(k); return new SimpleValueWrapper(value); } catch (SerializationException | ClassNotFoundException e) { log.warn("Class {} deserialization issue: {}", className, e.getMessage()); log.trace("", e); return null; } } }
From source file:com.minyisoft.webapp.core.utils.spring.cache.redis.RedisCache.java
protected ValueWrapper _get(Jedis jedis, Object key) { byte[] bs = jedis.get(computeKey(key)); return bs == null ? null : new SimpleValueWrapper(deserializer.convert(bs)); }
From source file:com.google.code.ssm.spring.SSMCache.java
@Override public ValueWrapper get(final Object key) { if (!cache.isEnabled()) { LOGGER.warn("Cache {} is disabled. Cannot get {} from cache", cache.getName(), key); return null; }/*from www.j a va2s.c o m*/ 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); }
From source file:com.zxy.commons.cache.RedisCache.java
/** * {@inheritDoc}//w ww . j a v a 2 s . c o m */ @Override public ValueWrapper putIfAbsent(Object key, Object value) { return redisTemplate.execute(new RedisCallback<ValueWrapper>() { public ValueWrapper doInRedis(RedisConnection connection) throws DataAccessException { byte[] keyb = SerializationUtils.serialize(key); byte[] valueb = SerializationUtils.serialize(value); connection.setNX(keyb, valueb); if (expires > 0) { connection.expire(keyb, expires); } return new SimpleValueWrapper(value); } }); }
From source file:grails.plugin.cache.GrailsConcurrentLinkedMapCache.java
private ValueWrapper toWrapper(Object value) { return (value != null ? new SimpleValueWrapper(fromStoreValue(value)) : null); }
From source file:com.couchbase.client.spring.cache.CouchbaseCache.java
@Override public final ValueWrapper get(final Object key) { String documentId = getDocumentId(key.toString()); SerializableDocument doc = client.get(documentId, SerializableDocument.class); if (doc == null) { return null; }// w w w.j a va 2s .c o m if (doc.content() == null) { return EMPTY_WRAPPER; } return new SimpleValueWrapper(doc.content()); }
From source file:net.eusashead.spring.gaecache.GaeCache.java
@Override public ValueWrapper get(Object key) { Assert.notNull(key);/*www. j a v a2 s . co m*/ Assert.isAssignable(GaeCacheKey.class, key.getClass()); GaeCacheKey cacheKey = GaeCacheKey.class.cast(key); Integer namespaceKey = getNamespaceKey(); String nsKey = getKey(namespaceKey, cacheKey); Object value = syncCache.get(nsKey); log.fine(String.format("Retrieving key %s (%s) from namespace %s (namespace key: %s), got %s", cacheKey.hashValue(), cacheKey.rawValue(), this.name, namespaceKey, value)); return (value != null ? new SimpleValueWrapper(value) : null); }
From source file:com.couchbase.client.spring.cache.CouchbaseCache.java
/** * {@inheritDoc}//w w w . j a v a2 s. c o m * <p> * Note that the atomicity in this Couchbase implementation is guaranteed for the insertion part. The detection of the * pre-existing key and thus skipping of the insertion is atomic. However, in such a case a get will have to be * performed to retrieve the pre-existing value. This get is not atomic and could see the key as deleted, in which * case it will return a {@link ValueWrapper} with a null content. */ @Override public ValueWrapper putIfAbsent(Object key, Object value) { if (value != null && !(value instanceof Serializable)) { throw new IllegalArgumentException(String.format("Value %s of type %s is not Serializable", value.toString(), value.getClass().getName())); } String documentId = getDocumentId(key.toString()); SerializableDocument doc = SerializableDocument.create(documentId, ttl, (Serializable) value); try { client.insert(doc); return null; } catch (DocumentAlreadyExistsException e) { SerializableDocument existingDoc = client.get(documentId, SerializableDocument.class); if (existingDoc == null) { return EMPTY_WRAPPER; } return new SimpleValueWrapper(existingDoc.content()); } }
From source file:org.springframework.cache.lru.LruCache.java
@SuppressWarnings("unchecked") @Override//from w w w. j ava 2 s .co m public ValueWrapper get(Object key) { Object value = mLruCache.get(key); return (value != null ? new SimpleValueWrapper(fromStoreValue(value)) : null); }