Issue
I'm using memcache on appengine. I inserted a json string:
private static CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory();;
private static Cache cache = cacheFactory.createCache(Collections.emptyMap());;
String data = "{\name\": \"jim\"}";
cache.put("1234", data);
now I'm trying to get the string from memcache and create a json object:
JSONObject dataObj = new JSONObject(cache.get("1234")); // log => {name: "john"}
this works for me well, and I get the expected JSON -> {name: "john"}
.
Now I am getting the data before I create the 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}
and now I am receiving the data in an byte Object -> {bytes: [12,..],empty: false}
What's going on? Isn't there an expected behavior?
EDIT
I will note that when on the memcach-console the value is saved ok -> {name: "john"}
Solution
Instead of
Object myData = cache.get("1234");
try
String myData = (String) cache.get("1234");
By the way, on App Engine I am using the following code:
MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
memcache.put("1234", object);
String myData = (String) memcache.get("1234");
Answered By - Andrei Volgin Answer Checked By - Terry (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.