Can I create multi hash table?

Anatol Pomozov anatol.pomozov at
Wed Sep 27 15:05:56 UTC 2006

Hi, all.

I would try to the develop idea of multidimensional hash that Mingqi started.

The last month idea of using Memcached for caching becomes very
popular in RubyOnRails community. You could find several recipes and
articles how to use MemCached with RoR.

And I would say that memcached hepls a lot with caching.

There is no problems with objects that uniquely defined by key. For
example models
'class User' defined by its id and we store it in memcached with key
There are no probls.

Another story with view fragments caching
Lets imagine example - on web page we have a list of products.
Content of this list depends on:
  * user - different users have different price calculation
algorithms, some of the users have discounts.
  * language that user uses. Product names shown in language that user
choose. Something like we have here
  * producer. Different producers have different list of products and
different prices, so we need to cache this fragments for each producer
  * ...

I would like to cache this fragment cause price calculation is very
expensive operation.

So to cache we need to use complex key like


Problem goes when we need to expire (remove from cache) subset of the records.

Lets imagine that some user A get 10% discount to all products. We
need to remove from cache ALL fragments that match Regexp


How to do it with Memcached?

There are also possible a lot of other cases. Like
  * We change Russian translation and would like to remove ALL
fragments for Russian language.
  * Producer changed price to its products for user C - we need to
remove all fragments with this producerID and user = C

On 9/27/06, Steven Grimm <sgrimm at> wrote:
>  You have a couple options. If flushing all person data is a very infrequent
> operation, you can do a "flush_all" command, which will flush the entire
> cache, including all your product data. That's by far the most efficient (on
> the memcached side, anyway) but obviously it means your application will
> have to repopulate the whole cache, not just the person data.
>  Alternately, if you need to flush all your person data often, you can add
> another prefix or suffix to your keys: a version number. When you want to
> flush the person data, just increase the version number you append to all
> your person keys. The old values will still be in the cache, but you will
> never look them up and they will eventually fall out of the cache because of
> the LRU algorithm.
>  There is no way to perform bulk operations on a subset of the values in the
> cache.
>  If you tell us a little more about why you want to flush your person data,
> one of us can probably offer some alternate approaches. Assuming, that is,
> that one of the two suggestions above isn't suitable for you.
anatol (

More information about the memcached mailing list