Data sharing in Couchbase's memcached implementation between Java and .Net -
i trying share data stored in couchbase memcached bucket between java , .net.
i able read string set in java in .net whenever try read string set in .net in java result null.
so possible exchange data between .net , java in memcache buckets in couchbase server.
thanks reply, figured out.
the reason .net able read strings set in java because enyimmemcached library interprets cached item string if not recognize flag.
so in order able read strings in java, created own custom transcoder extending spyobject , set in away such ignores flag. pass custom transcoder call this,
_obj = getmemcachedclient().get(key, new stringtranscoder()) my stringtranscoder class looks this,
/** * copyright (c) 2006-2009 dustin sallings * * permission hereby granted, free of charge, person obtaining copy * of software , associated documentation files (the "software"), deal * in software without restriction, including without limitation rights * use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of software, , permit persons whom software * furnished so, subject following conditions: * * above copyright notice , permission notice shall included in * copies or substantial portions of software. * * software provided "as is", without warranty of kind, express or * implied, including not limited warranties of merchantability, * fitness particular purpose , noninfringement. in no event shall * authors or copyright holders liable claim, damages or other * liability, whether in action of contract, tort or otherwise, arising * from, out of or in connection software or use or other dealing * in software. */ package cachingjavatestapp; import java.io.ioexception; import net.spy.memcached.cacheddata; import net.spy.memcached.compat.spyobject; import net.spy.memcached.transcoders.transcoder; import net.spy.memcached.transcoders.transcoderutils; /** * transcoder serializes , unserializes longs. */ public final class stringtranscoder extends spyobject implements transcoder<string> { private static final int flags = 0; public boolean asyncdecode(cacheddata d) { return false; } public cacheddata encode(java.lang.string l) { try{ return new cacheddata(flags, l.getbytes("utf-8"), getmaxsize()); } catch (exception e){ return null; } } public string decode(cacheddata d) { try{ return new string(d.getdata(), "utf-8"); }catch(exception e){ return null; } } public int getmaxsize() { return cacheddata.max_size; } } in order able exchange data between .net , java. used json.net library , gson library serialize objects , pass json strings memcached gets picked string deserialized using json libraries.
regards,
Comments
Post a Comment