上面方法实际上就是encode(Object o)方法的逆向实现,即将字节数组转化成Object对象。注意第4行调用了deserialize(byte[] in)方法,该方法代码如下(省略了catch、finally部分):
protected Object deserialize(byte[] in) { Object rv = null; ByteArrayInputStream bis = null; ObjectInputStream is = null; try { if (in != null) { bis = new ByteArrayInputStream(in); is = new ObjectInputStream(bis) { @Override protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { try { //When class is not found,try to load it from context class loader. return super.resolveClass(desc); } catch (ClassNotFoundException e) { return Thread.currentThread().getContextClassLoader().loadClass(desc.getName()); } } }; rv = is.readObject(); } } ... return rv; }上述代码就是反序列化对象并返回。每次反序列化操作,得到的都是一个全新对象,对该新对象进行的任何操作并不会影响memcached中存储的值。