سؤال

Does libmemcached do any local caching of objects? Another way to ask would be if there's a 1:1 correspondence between calls to memcached_get() and requests that go out over the network? If I request object "A" twice in a row, is it making 2 requests?

If it doesn't do any caching, are there preferred methods or libraries for doing that caching?

Edit: @mikewied's answer below showed that probably a bit more explanation is in order. My use case is as follows: the data I would be storing in the caches is immutable, so I don't have to worry about invalidation; the desire for client side (in-process) caching is driven by the fact that the application will be accessing large numbers of cached objects repeatedly, so incurring a network round trip each time ends up slowing the app down quite a bit.

هل كانت مفيدة؟

المحلول

libmemcached does not do any caching and if you want to do this then you would probably have to implement something yourself. I debated whether or not to just post this as a comment since I don't have any recommendations for client side caching libraries, but I decided to post as an answer since I'm curious why client side caching is so important your application (and others who might also be reading this question). First off, if you do this, your going to have a cache invalidation problem. Imagine two clients setting data to the same memcached server. If your clients get out of sync they will be serving up cold data. Clearly you can use a ttl on each value you store client side, but you'll still have some inconsistencies. Maybe this is okay, but then you have to ask yourself if the sub-millisecond latencies provided to you by memcached are really too slow for your application. Also keep in mind that your users might be far from your data center and it might take a second or two to get them the data once it leaves your application. In this case is sub-millisecond really too slow considering all of the other added latency? The last thing I want to mention is that if you set up memcached on the right hardware and write your applications properly you can do 200,000 ops/sec on commodity hardware. I've even seen benchmarks where people have done over 500,000 ops/sec on a single server. This means you more likely to saturate your network before you overload memcached. (Maybe this is the issue your trying to avoid)

Anyways, I know this probably isn't exactly the answer your looking for, but I've seen a lot of people ask for client side caching stuff lately and in a lot of cases I just don't understand why people think it's necessary. To be clear there are good reasons why you might want to add this your application, but I think anyone thinks about adding it should really try to figure out if it's necessary. I hope this doesn't come off as harsh. I really mean it to be helpful. You might have the perfect use case and if so then maybe someone else will find some of the things I have added here useful.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top