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

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

本文整理了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

@SuppressWarnings("unchecked")
@Override
public Session get(final Builder builder) {
 String key = key(builder.sessionId());
 Map<String, String> attrs = (Map<String, String>) memcached.get(key);
 if (attrs == null || attrs.size() == 0) {
  // expired
  return null;
 }
 // touch session
 memcached.touch(key, timeout);
 return builder
   .accessedAt(Long.parseLong(attrs.remove("_accessedAt")))
   .createdAt(Long.parseLong(attrs.remove("_createdAt")))
   .savedAt(Long.parseLong(attrs.remove("_savedAt")))
   .set(attrs)
   .build();
}

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

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

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

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

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

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

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

@Override
public T get( String key )
{
  Object value = client.get( prefix( key ), new SerializingTranscoder() );
  client.touch( prefix( key ), expiration );
  if( value == null )
  {
    return null;
  }
  return valueType.cast( value );
}

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

@SuppressWarnings("unchecked")
@Override
public Session get(final Builder builder) {
 String key = key(builder.sessionId());
 Map<String, String> attrs = (Map<String, String>) memcached.get(key);
 if (attrs == null || attrs.size() == 0) {
  // expired
  return null;
 }
 // touch session
 memcached.touch(key, timeout);
 return builder
   .accessedAt(Long.parseLong(attrs.remove("_accessedAt")))
   .createdAt(Long.parseLong(attrs.remove("_createdAt")))
   .savedAt(Long.parseLong(attrs.remove("_savedAt")))
   .set(attrs)
   .build();
}

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

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

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

@Test
public void whenPutIfAbsentAndNoCachedValueThenReturnNewValue() {
  when(memcachedClient.get(anyString()))
      .thenReturn(NAMESPACE_KEY_VALUE)
      .thenReturn(null)
      .thenReturn(NAMESPACE_KEY_VALUE);
  Cache.ValueWrapper actual = memcachedCache.putIfAbsent(CACHED_OBJECT_KEY, newCachedValue);
  assertThat(actual.get()).isEqualTo(newCachedValue);
  verify(memcachedClient, times(2)).get(namespaceKey);
  verify(memcachedClient).get(memcachedKey);
  verify(memcachedClient).set(eq(memcachedKey), anyInt(), eq(newCachedValue));
  verify(memcachedClient).touch(namespaceKey, CACHE_EXPIRATION);
}

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

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

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

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

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

@Test
public void whenPutAndNamespaceMissingThenSetNamespace() {
  when(memcachedClient.get(namespaceKey)).thenReturn(null);
  memcachedCache.put(CACHED_OBJECT_KEY, cachedValue);
  verify(memcachedClient).get(namespaceKey);
  verify(memcachedClient).set(eq(namespaceKey), eq(CACHE_EXPIRATION), anyString());
  verify(memcachedClient).set(endsWith(CACHED_OBJECT_KEY), eq(CACHE_EXPIRATION), eq(cachedValue));
  verify(memcachedClient).touch(namespaceKey, CACHE_EXPIRATION);
}

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

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

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

@Test
public void whenPutNullThenStoreNullValueInstance() {
  when(memcachedClient.get(namespaceKey)).thenReturn(NAMESPACE_KEY_VALUE);
  memcachedCache.put(CACHED_OBJECT_KEY, null);
  verify(memcachedClient).get(namespaceKey);
  verify(memcachedClient).set(memcachedKey, CACHE_EXPIRATION, NullValue.INSTANCE);
  verify(memcachedClient).touch(namespaceKey, CACHE_EXPIRATION);
}

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

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

相关文章