net.spy.memcached.MemcachedClient.touch()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(167)

本文整理了Java中net.spy.memcached.MemcachedClient.touch()方法的一些代码示例,展示了MemcachedClient.touch()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MemcachedClient.touch()方法的具体详情如下:
包路径:net.spy.memcached.MemcachedClient
类名称:MemcachedClient
方法名:touch

MemcachedClient.touch介绍

[英]Touch the given key to reset its expiration time with the default transcoder.
[中]触按给定键可使用默认转码器重置其到期时间。

代码示例

代码示例来源:origin: jooby-project/jooby

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. public Session get(final Builder builder) {
  4. String key = key(builder.sessionId());
  5. Map<String, String> attrs = (Map<String, String>) memcached.get(key);
  6. if (attrs == null || attrs.size() == 0) {
  7. // expired
  8. return null;
  9. }
  10. // touch session
  11. memcached.touch(key, timeout);
  12. return builder
  13. .accessedAt(Long.parseLong(attrs.remove("_accessedAt")))
  14. .createdAt(Long.parseLong(attrs.remove("_createdAt")))
  15. .savedAt(Long.parseLong(attrs.remove("_savedAt")))
  16. .set(attrs)
  17. .build();
  18. }

代码示例来源:origin: net.spy/spymemcached

  1. /**
  2. * Touch the given key to reset its expiration time with the default
  3. * transcoder.
  4. *
  5. * @param key the key to fetch
  6. * @param exp the new expiration to set for the given key
  7. * @return a future that will hold the return value of whether or not the
  8. * fetch succeeded
  9. * @throws IllegalStateException in the rare circumstance where queue is too
  10. * full to accept any more requests
  11. */
  12. @Override
  13. public <T> OperationFuture<Boolean> touch(final String key, final int exp) {
  14. return touch(key, exp, transcoder);
  15. }

代码示例来源:origin: com.google.code.simple-spring-memcached/spymemcached

  1. /**
  2. * Touch the given key to reset its expiration time with the default
  3. * transcoder.
  4. *
  5. * @param key the key to fetch
  6. * @param exp the new expiration to set for the given key
  7. * @return a future that will hold the return value of whether or not the
  8. * fetch succeeded
  9. * @throws IllegalStateException in the rare circumstance where queue is too
  10. * full to accept any more requests
  11. */
  12. public <T> OperationFuture<Boolean> touch(final String key, final int exp) {
  13. return touch(key, exp, transcoder);
  14. }

代码示例来源:origin: com.amazonaws/elasticache-java-cluster-client

  1. /**
  2. * Touch the given key to reset its expiration time with the default
  3. * transcoder.
  4. *
  5. * @param key the key to fetch
  6. * @param exp the new expiration to set for the given key
  7. * @return a future that will hold the return value of whether or not the
  8. * fetch succeeded
  9. * @throws IllegalStateException in the rare circumstance where queue is too
  10. * full to accept any more requests
  11. */
  12. @Override
  13. public <T> OperationFuture<Boolean> touch(final String key, final int exp) {
  14. return touch(key, exp, transcoder);
  15. }

代码示例来源:origin: apache/attic-polygene-java

  1. @Override
  2. public T get( String key )
  3. {
  4. Object value = client.get( prefix( key ), new SerializingTranscoder() );
  5. client.touch( prefix( key ), expiration );
  6. if( value == null )
  7. {
  8. return null;
  9. }
  10. return valueType.cast( value );
  11. }

代码示例来源:origin: org.jooby/jooby-spymemcached

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. public Session get(final Builder builder) {
  4. String key = key(builder.sessionId());
  5. Map<String, String> attrs = (Map<String, String>) memcached.get(key);
  6. if (attrs == null || attrs.size() == 0) {
  7. // expired
  8. return null;
  9. }
  10. // touch session
  11. memcached.touch(key, timeout);
  12. return builder
  13. .accessedAt(Long.parseLong(attrs.remove("_accessedAt")))
  14. .createdAt(Long.parseLong(attrs.remove("_createdAt")))
  15. .savedAt(Long.parseLong(attrs.remove("_savedAt")))
  16. .set(attrs)
  17. .build();
  18. }

代码示例来源:origin: org.opensaml/opensaml-storage-impl

  1. for (String key : keySet) {
  2. logger.debug("Updating expiration of key {} to {}", key, expiry);
  3. results.add(memcacheClient.touch(key, expiry));

代码示例来源:origin: sixhours-team/memcached-spring-boot

  1. @Test
  2. public void whenPutIfAbsentAndNoCachedValueThenReturnNewValue() {
  3. when(memcachedClient.get(anyString()))
  4. .thenReturn(NAMESPACE_KEY_VALUE)
  5. .thenReturn(null)
  6. .thenReturn(NAMESPACE_KEY_VALUE);
  7. Cache.ValueWrapper actual = memcachedCache.putIfAbsent(CACHED_OBJECT_KEY, newCachedValue);
  8. assertThat(actual.get()).isEqualTo(newCachedValue);
  9. verify(memcachedClient, times(2)).get(namespaceKey);
  10. verify(memcachedClient).get(memcachedKey);
  11. verify(memcachedClient).set(eq(memcachedKey), anyInt(), eq(newCachedValue));
  12. verify(memcachedClient).touch(namespaceKey, CACHE_EXPIRATION);
  13. }

代码示例来源:origin: sixhours-team/memcached-spring-boot

  1. @Test
  2. public void whenGetWithValueLoaderAndCachedValueMissingThenReturnValueLoaderNull() {
  3. when(memcachedClient.get(namespaceKey)).thenReturn(NAMESPACE_KEY_VALUE);
  4. when(memcachedClient.get(memcachedKey)).thenReturn(null);
  5. Object actual = memcachedCache.get(CACHED_OBJECT_KEY, () -> valueLoaderNullValue);
  6. assertThat(actual).isEqualTo(null);
  7. verify(memcachedClient, times(3)).get(namespaceKey);
  8. verify(memcachedClient, times(2)).get(memcachedKey);
  9. verify(memcachedClient).set(memcachedKey, CACHE_EXPIRATION, valueLoaderNullValue);
  10. verify(memcachedClient).touch(namespaceKey, CACHE_EXPIRATION);
  11. }

代码示例来源:origin: sixhours-team/memcached-spring-boot

  1. @Test
  2. public void whenGetWithValueLoaderAndCachedValueMissingThenReturnValueLoaderValue() {
  3. when(memcachedClient.get(namespaceKey)).thenReturn(NAMESPACE_KEY_VALUE);
  4. when(memcachedClient.get(memcachedKey)).thenReturn(null);
  5. Object actual = memcachedCache.get(CACHED_OBJECT_KEY, () -> valueLoaderValue);
  6. assertThat(actual).isEqualTo(valueLoaderValue);
  7. verify(memcachedClient, times(3)).get(namespaceKey);
  8. verify(memcachedClient, times(2)).get(memcachedKey);
  9. verify(memcachedClient).set(memcachedKey, CACHE_EXPIRATION, valueLoaderValue);
  10. verify(memcachedClient).touch(namespaceKey, CACHE_EXPIRATION);
  11. }

代码示例来源:origin: sixhours-team/memcached-spring-boot

  1. @Test
  2. public void whenPutAndNamespaceMissingThenSetNamespace() {
  3. when(memcachedClient.get(namespaceKey)).thenReturn(null);
  4. memcachedCache.put(CACHED_OBJECT_KEY, cachedValue);
  5. verify(memcachedClient).get(namespaceKey);
  6. verify(memcachedClient).set(eq(namespaceKey), eq(CACHE_EXPIRATION), anyString());
  7. verify(memcachedClient).set(endsWith(CACHED_OBJECT_KEY), eq(CACHE_EXPIRATION), eq(cachedValue));
  8. verify(memcachedClient).touch(namespaceKey, CACHE_EXPIRATION);
  9. }

代码示例来源:origin: org.opensaml/opensaml-storage-impl

  1. /** {@inheritDoc} */
  2. @Override
  3. public boolean updateExpiration(@Nonnull @NotEmpty final String context,
  4. @Nonnull @NotEmpty final String key,
  5. @Nullable @Positive final Long expiration) throws IOException {
  6. Constraint.isNotNull(StringSupport.trimOrNull(context), "Context cannot be null or empty");
  7. Constraint.isNotNull(StringSupport.trimOrNull(key), "Key cannot be null or empty");
  8. final int expiry = MemcachedStorageRecord.expiry(expiration);
  9. Constraint.isGreaterThan(-1, expiry, "Expiration must be null or positive");
  10. final String namespace = lookupNamespace(context);
  11. if (namespace == null) {
  12. logger.debug("Namespace for context {} does not exist", context);
  13. return false;
  14. }
  15. final String cacheKey = memcachedKey(namespace, key);
  16. logger.debug("Updating expiration for entry at {} for context={}, key={}", cacheKey, context, key);
  17. return handleAsyncResult(memcacheClient.touch(cacheKey, expiry));
  18. }

代码示例来源:origin: sixhours-team/memcached-spring-boot

  1. @Test
  2. public void whenPutNullThenStoreNullValueInstance() {
  3. when(memcachedClient.get(namespaceKey)).thenReturn(NAMESPACE_KEY_VALUE);
  4. memcachedCache.put(CACHED_OBJECT_KEY, null);
  5. verify(memcachedClient).get(namespaceKey);
  6. verify(memcachedClient).set(memcachedKey, CACHE_EXPIRATION, NullValue.INSTANCE);
  7. verify(memcachedClient).touch(namespaceKey, CACHE_EXPIRATION);
  8. }

代码示例来源:origin: sixhours-team/memcached-spring-boot

  1. @Override
  2. public void put(Object key, Object value) {
  3. this.memcachedClient.set(memcachedKey(key), this.memcacheCacheMetadata.expiration(), toStoreValue(value));
  4. this.memcachedClient.touch(this.memcacheCacheMetadata.namespaceKey(), this.memcacheCacheMetadata.expiration());
  5. }

相关文章