Amazon Elasticache used as Memcached to store a Inputstream (converted to byte array) like so
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();
The stored byteArray is read like so
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();
The byte Array returned is always "null" except for the first time the application starts.
My Question
- Why Memcached is returning a null byte array except for the first time?
- How to check if the the byte array is successfully written to the Memcached?