org.springframework.cache.support.SimpleValueWrapper Java Examples

The following examples show how to use org.springframework.cache.support.SimpleValueWrapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArcusCache.java    From arcus-spring with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: SSMCache.java    From simple-spring-memcached with MIT License 6 votes vote down vote up
@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);
}
 
Example #3
Source File: ConfigurableGuavaCacheManager.java    From haven-platform with Apache License 2.0 5 votes vote down vote up
private com.google.common.cache.Cache<Object, SimpleValueWrapper> buildCache(CacheConfig cacheConfig) {
    CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
    if(cacheConfig.getExpireAfterWrite() >= 0) {
        builder.expireAfterWrite(cacheConfig.getExpireAfterWrite(), TimeUnit.MILLISECONDS);
    }
    return builder.build();
}
 
Example #4
Source File: SpringCacheManagerWrapper.java    From es with Apache License 2.0 5 votes vote down vote up
@Override
public Object get(Object key) throws CacheException {
    Object value = springCache.get(key);
    if (value instanceof SimpleValueWrapper) {
        return ((SimpleValueWrapper) value).get();
    }
    return value;
}
 
Example #5
Source File: ArcusCache.java    From arcus-spring with Apache License 2.0 5 votes vote down vote up
/**
 * @param key key
 * @param value value
 * @return 지정된 키에 대한 캐시 아이템이 존재하지 않았으며 지정된 값을 캐시에 저장하였다면 null을 리턴,
 * 캐시 아이템이 이미 존재하였다면 지정된 키에 대한 값을 불러와 리턴한다. 값을 불러올 때 비원자적으로
 * 수행되기 때문에 중간에 다른 캐시 연산 수행으로 인하여 새로운 값이 리턴 될 수 있으며 혹은 캐시 만료로 인해
 * ValueWrapper의 내부 value가 null이 되어 리턴될 수 있다.
 */
@Override
public ValueWrapper putIfAbsent(Object key, Object value) {
  try {
    String arcusKey = createArcusKey(key);
    logger.debug("trying to add key: {}, value: {}", arcusKey,
            value != null ? value.getClass().getName() : null);

    if (value == null) {
      throw new IllegalArgumentException("arcus cannot add NULL value. key: " +
              arcusKey);
    }

    Future<Boolean> future;

    if (operationTranscoder != null) {
      future = arcusClient.add(arcusKey, expireSeconds, value,
              operationTranscoder);
    } else {
      future = arcusClient.add(arcusKey, expireSeconds, value);
    }

    boolean added = future.get(timeoutMilliSeconds,
            TimeUnit.MILLISECONDS);

    return added ? null : new SimpleValueWrapper(getValue(arcusKey)); // FIXME: maybe returned with a different value.
  } catch (Exception e) {
    logger.debug(e.getMessage());
    throw toRuntimeException(e);
  }
}
 
Example #6
Source File: SimpleSpringMemcached.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Override
public ValueWrapper get(Object key) {
	Assert.notNull(key, "key parameter is mandatory");
	Assert.isAssignable(String.class, key.getClass());
	Object result = this.memcachedClientIF.get((String) key);
	return result != null ? new SimpleValueWrapper(result) : null;
}
 
Example #7
Source File: RedissonCache.java    From redisson with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #8
Source File: CustomConcurrentMapCache.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ValueWrapper get(Object key) {
    ValueWrapper wrapper = super.get(key);
    if (wrapper == null) {
        return null;
    }
    if (wrapper.get() instanceof Nullable) {
        return new SimpleValueWrapper(null);
    } else {
        return wrapper;
    }
}
 
Example #9
Source File: MemcachedCacheManager.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
//TODO implementation here doesn't guarantee the atomicity.
//Without atomicity, this method should not be invoked
public ValueWrapper putIfAbsent(Object key, Object value) {
    byte[] existing = memcachedCache.get(key);
    if (existing == null) {
        memcachedCache.put(key, value);
        return null;
    } else {
        return new SimpleValueWrapper(SerializationUtils.deserialize(existing));
    }
}
 
Example #10
Source File: MemcachedCacheManager.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public ValueWrapper get(Object key) {
    byte[] value = memcachedCache.get(key);
    if (value == null) {
        return null;
    }
    return new SimpleValueWrapper(SerializationUtils.deserialize(value));
}
 
Example #11
Source File: DefaultDownloadIdCacheTest.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Test
@Description("Verifies that retrieving a value for a specific key is delegated to the CacheManager implementation")
public void getValueReturnsTheAssociatedValueForKey() {
    final String knownKey = "12345";
    final DownloadArtifactCache knownValue = new DownloadArtifactCache(DownloadType.BY_SHA1, knownKey);

    when(cacheMock.get(knownKey)).thenReturn(new SimpleValueWrapper(knownValue));

    final DownloadArtifactCache downloadArtifactCache = underTest.get(knownKey);

    assertThat(downloadArtifactCache).isEqualTo(knownValue);
}
 
Example #12
Source File: UserSessionsController.java    From infinispan-simple-tutorials with Apache License 2.0 5 votes vote down vote up
@GetMapping("/sessions/{id}")
public String sessionContent(@PathVariable String id) {
    SimpleValueWrapper simpleValueWrapper = (SimpleValueWrapper) cacheManager.getCache("sessions").get(id);
    if (simpleValueWrapper == null) {
        return "Session not found";
    }
    MapSession mapSession = (MapSession) simpleValueWrapper.get();
    return "Latest " + mapSession.getAttribute(LATEST_SESSION_VALUE);
}
 
Example #13
Source File: CacheDelegate.java    From java-platform with Apache License 2.0 5 votes vote down vote up
private ValueWrapper toValueWrapper(Object value) {
	if (value == null) {
		return null;
	}
	if (value == NullValue.NULL) {
		return NullValue.NULL;
	}
	return new SimpleValueWrapper(value);
}
 
Example #14
Source File: CacheErrorHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void getAndPutFail() {
	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

	Object counter = this.simpleService.get(0L);

	willReturn(new SimpleValueWrapper(2L)).given(this.cache).get(0L);
	Object counter2 = this.simpleService.get(0L);
	Object counter3 = this.simpleService.get(0L);
	assertNotSame(counter, counter2);
	assertEquals(counter2, counter3);
}
 
Example #15
Source File: SpringCacheManagerWrapper.java    From PhrackCTF-Platform-Personal with Apache License 2.0 5 votes vote down vote up
public Object get(Object key) throws CacheException {
    Object value = springCache.get(key);
    if (value instanceof SimpleValueWrapper) {
        return ((SimpleValueWrapper) value).get();
    }
    return value;
}
 
Example #16
Source File: SpringCacheManagerWrapper.java    From PhrackCTF-Platform-Team with Apache License 2.0 5 votes vote down vote up
public Object get(Object key) throws CacheException {
    Object value = springCache.get(key);
    if (value instanceof SimpleValueWrapper) {
        return ((SimpleValueWrapper) value).get();
    }
    return value;
}
 
Example #17
Source File: SpringCacheManagerWrapper.java    From roncoo-pay with Apache License 2.0 5 votes vote down vote up
@Override
public Object get(Object key) throws CacheException {
	Object value = springCache.get(key);
	if (value instanceof SimpleValueWrapper) {
		return ((SimpleValueWrapper) value).get();
	}
	return value;
}
 
Example #18
Source File: CacheManagerWrapper.java    From cms with Apache License 2.0 5 votes vote down vote up
@Override
public Object get(Object key) throws CacheException {
	Object value = springCache.get(key);
	if (value instanceof SimpleValueWrapper) {
		return ((SimpleValueWrapper) value).get();
	}
	return value;
}
 
Example #19
Source File: CacheErrorHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #20
Source File: MemcachedCacheManager.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public ValueWrapper get(Object key) {
    byte[] value = memcachedCache.get(key);
    if (value == null) {
        return null;
    }
    return new SimpleValueWrapper(SerializationUtils.deserialize(value));
}
 
Example #21
Source File: MemcachedCacheManager.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
//TODO implementation here doesn't guarantee the atomicity.
//Without atomicity, this method should not be invoked
public ValueWrapper putIfAbsent(Object key, Object value) {
    byte[] existing = memcachedCache.get(key);
    if (existing == null) {
        memcachedCache.put(key, value);
        return null;
    } else {
        return new SimpleValueWrapper(SerializationUtils.deserialize(existing));
    }
}
 
Example #22
Source File: CacheErrorHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void getAndPutFail() {
	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

	Object counter = this.simpleService.get(0L);

	willReturn(new SimpleValueWrapper(2L)).given(this.cache).get(0L);
	Object counter2 = this.simpleService.get(0L);
	Object counter3 = this.simpleService.get(0L);
	assertNotSame(counter, counter2);
	assertEquals(counter2, counter3);
}
 
Example #23
Source File: EhCacheCache.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Nullable
private ValueWrapper toValueWrapper(@Nullable Element element) {
	return (element != null ? new SimpleValueWrapper(element.getObjectValue()) : null);
}
 
Example #24
Source File: ArcusCache.java    From arcus-spring with Apache License 2.0 4 votes vote down vote up
private ValueWrapper toValueWrapper(Object value) {
  return (value != null ? new SimpleValueWrapper(value) : null);
}
 
Example #25
Source File: InstrumentedEhCacheCache.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public ValueWrapper get(Object key) {
    Element element = this.cache.get(key);
    return (element != null ? new SimpleValueWrapper(element.getObjectValue()) : null);
}
 
Example #26
Source File: InstrumentedEhCacheCache.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public ValueWrapper putIfAbsent(Object key, Object value) {
    Element existingElement = this.cache.putIfAbsent(new Element(key, value));
    return (existingElement != null ? new SimpleValueWrapper(existingElement.getObjectValue()) : null);
}
 
Example #27
Source File: EhCacheCache.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Nullable
private ValueWrapper toValueWrapper(@Nullable Element element) {
	return (element != null ? new SimpleValueWrapper(element.getObjectValue()) : null);
}
 
Example #28
Source File: MemcacheCache.java    From bbs with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 根据key得到一个ValueWrapper,然后调用其get方法获取值
 */
@Override
public ValueWrapper get(Object key) {
	Object aValue = memcachedManager.getCache(getName(), objectToString(key));
	return (aValue != null ? new SimpleValueWrapper(aValue) : null);
}
 
Example #29
Source File: Cache.java    From smart-cache with Apache License 2.0 4 votes vote down vote up
private ValueWrapper toValueWrapper(Object value) {
    return (value != null ? new SimpleValueWrapper(value) : null);
}
 
Example #30
Source File: InstrumentedEhCacheCache.java    From kylin with Apache License 2.0 4 votes vote down vote up
@Override
public ValueWrapper putIfAbsent(Object key, Object value) {
    Element existingElement = this.cache.putIfAbsent(new Element(key, value));
    return (existingElement != null ? new SimpleValueWrapper(existingElement.getObjectValue()) : null);
}