如何从 App Engine 上的 memcached 获取字符串 - java

how to get a string from memcach on appengine - java

我在 Appengine 上使用内存缓存。 我插入了一个 json 字符串:

private static CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory();;
private static Cache cache = cacheFactory.createCache(Collections.emptyMap());;
String data = "{\name\": \"jim\"}";
cache.put("1234", data);

现在我正在尝试从内存缓存中获取字符串并创建一个 json 对象:

JSONObject dataObj =   new JSONObject(cache.get("1234")); // log  => {name: "john"}

这很适合我,我得到了预期的 JSON -> {name: "john"}

现在我在创建 json 之前获取数据;

Object myData = cache.get("1234");
JSONObject dataObj =   new JSONObject(myData); // log => {"bytes":[123,34,110,97,109,101,34,58,34,106,111,104,110,34,125],"empty":false}

现在我正在接收字节对象中的数据 -> {bytes: [12,..],empty: false}

这是怎么回事?没有预期的行为吗?

编辑 我会注意到,当在 memcach-console 上时,值保存正常 -> {name: "john"}

而不是

Object myData = cache.get("1234");

尝试

String myData = (String) cache.get("1234");

顺便说一下,我在 App Engine 上使用以下代码:

MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
memcache.put("1234", object);
String myData = (String) memcache.get("1234");