4

Amazon Elasticache 用作 Memcached 来存储 Inputstream(转换为字节数组),就像这样

private static final int MEMCACHED_TIME_TO_LIVE = 15 * 60;
InputStream stream = item.openStream();

byte[] byteArray = IOUtils.toByteArray(stream);


MemcachedClient memcachedClient = new MemcachedClient(new InetSocketAddress(AMAZON_ELASTICACHE_CLUSTER_ENDPOINT,AMAZON_ELASTICACHE_CLUSTER_PORT));
String key = name;

Future<Boolean> result = memcachedClient.set(key, MEMCACHED_TIME_TO_LIVE,byteArray);

memcachedClient.shutdown();

存储的 byteArray 是这样读取的

MemcachedClient memcachedClient = new MemcachedClient(new InetSocketAddress(AMAZON_ELASTICACHE_CLUSTER_ENDPOINT,
                    AMAZON_ELASTICACHE_CLUSTER_PORT));

String key = name;
byte[] byteArray = (byte[]) memcachedClient.get(key);
memcachedClient.shutdown();

返回的字节数组始终为“null”,除非应用程序第一次启动。

我的问题

  1. 为什么 Memcached 除了第一次返回空字节数组?
  2. 如何检查字节数组是否成功写入 Memcached?
4

0 回答 0