using memcache with multi ClientAPI multi platforms and languages

When your system is large, compose by several programs, in several languages. If every programs need to access memcacheD, you should use the correct ClientAPI to make them talk with each other.
Of course, if you set value by PHP, you get value by PHP, it works. If you set value by Java, then you get value by other Java program, it work too.

BUT, this time (this post time), if PHP says, maybe Java can’t hear, C# can’t here, and vice versa.

in PHP, $memcacheClient->set(“test”,”lockevn”);     // it will go to memcache server

in Java, Object oValue = oMemcacheClient.get(“test”) ;      // it will return null, supprise!!! @:@

I have some experience with Java, PHP. PHP website (using default pecl extension module) set value to memcache, if Java program need to get that value, you should use http://bleu.west.spy.net/~dustin/projects/memcached/ ClientAPI (at the time of this post). The other won’t work. Follow this link to get more info.

I do not test .NET client   http://www.codeplex.com/EnyimMemcached

You also need to store value as native format, only use 32bit integer, or string. If you put PHP object, Java program can not understand it, neither the C# program.

If your really need to store object, serialize it (to XML, JSON, … encode with UTF-8) BEFORE put it in memcache. The others must deserialize after get that value. Believe me, do that will save you a lot of time.

There is a similar alternative project on Windows: Velocity from MS
http://www.microsoft.com/downloads/details.aspx?FamilyId=B24C3708-EEFF-4055-A867-19B5851E7CD2&displaylang=en

And an alternate one
http://www.sharedcache.com/cms/

Summary

memcache is good, but it make only to store data, only data, it does not like “object” things, don’t push it too hard. If you want some program say and other “different language” program hear, check it carefully, ask the ClientAPI author if it does not work. You should use native data format for value (int and string only), do serialize by yourself if you want to store data object.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s