Re: how to flush all objects of a particular cache ??

1,712 views
Skip to first unread message
Message has been deleted

Henrik Schröder

unread,
Sep 19, 2008, 10:46:38 AM9/19/08
to memc...@googlegroups.com
I'm not familiar with the memcached taglib, but generally you cannot delete groups of keys from memcached without knowing the exact key name. This is a very common problem because you don't always know exactly what keys you have created that belong to a certain group, you only know that you want to invalidate the whole group.

We solve this in our products by doing a double fetch, we store a prefix under the group name, and then all keys that belong to the group gets this prefix prepended to them. If you then change the prefix for a group, you invalidate all the keys in that group. I have absolutely no idea if you can do this with the taglib (I'm guessing not), but it could perhaps be implemented as a feature of the taglib itself?


/Henrik Schröder

On Fri, Sep 19, 2008 at 7:52 AM, vp <vijaye...@gmail.com> wrote:

Hii,


I am using the memcached taglib . most of the pages have pagination ie
the key is like topis_1 , topics_2 ... , so they all have a common
group Name "Topic"


Whenever a new topic is added or deleted , i need to flush all the
cached pages in group Topic.

i have added a flush tag on action :

 <cache:flush scope="application" groups="Topic"/>

but this gives an error :
According to the TLD or the tag file, attribute key is mandatory for
tag flush


How can this problem be resolved ?


Any help will be appreciated .

Thanking in advance .

vp

unread,
Sep 24, 2008, 7:40:42 AM9/24/08
to memcached
Hey , can you tell me exactly how do you do the prepending

On Sep 19, 7:46 pm, "Henrik Schröder" <skro...@gmail.com> wrote:
> I'm not familiar with the memcached taglib, but generally you cannot delete
> groups of keys from memcached without knowing the exact key name. This is a
> very common problem because you don't always know exactly what keys you have
> created that belong to a certain group, you only know that you want to
> invalidate the whole group.
>
> We solve this in our products by doing a double fetch, we store a prefix
> under the group name, and then all keys that belong to the group gets this
> prefix prepended to them. If you then change the prefix for a group, you
> invalidate all the keys in that group. I have absolutely no idea if you can
> do this with the taglib (I'm guessing not), but it could perhaps be
> implemented as a feature of the taglib itself?
>
> /Henrik Schröder
>

Boris Partensky

unread,
Sep 24, 2008, 8:17:53 AM9/24/08
to memc...@googlegroups.com
This is described pretty well in FAQ: (http://www.socialtext.net/memcached/index.cgi?faq)

Namespaces

memcached does not support namespaces. However, there are some options to simulate them.

Simulating Namespaces with key prefixes

If you simply want to avoid key colision between different types of data, simply prefix your key with a useful string. For example: "user_12345", "article_76890".

Deleting by Namespace

While memcached does not support any type of wildcard deleting or deletion by namespace (since there are not namespaces), there are some tricks that can be used to simulate this. They do require extra trips to the memcached servers however.

Example, in PHP, for using a namespace called foo:

$ns_key = $memcache->get("foo_namespace_key");

// if not set, initialize it
if($ns_key===false) $memcache->set("foo_namespace_key", rand(1, 10000));

$my_key = "foo_".$ns_key."_12345";

To clear the namespace do:

$memcache->increment("foo_namespace_key");

--
--Boris

vp

unread,
Sep 24, 2008, 9:47:29 AM9/24/08
to memcached
Thanx !!!

On Sep 24, 5:17 pm, "Boris Partensky" <boris.parten...@gmail.com>
wrote:

Stephen Johnston

unread,
Sep 24, 2008, 10:11:24 AM9/24/08
to memc...@googlegroups.com
We do a similar sort of thing, but instead of using a "namespace" we have keys that have a parent key. We check the "parent" key before checking the child. If the parent is marked as invalidated or is non-existent then we treat that as the state of the child. If the parent exists, then we check the state of the child like usual.
 
-Stephen

Aaron Stone

unread,
Oct 31, 2008, 9:13:54 PM10/31/08
to memc...@googlegroups.com
That sounds like a great solution except for the doubled request
overhead... *thinks out loud for benefit of mailing list archives*
...batched requests, so you GETQ the parent and GET the child and then
you have everything you need to know about whether the child data is
valid.

Aaron

dormando

unread,
Nov 2, 2008, 2:25:50 AM11/2/08
to memc...@googlegroups.com
If the parent key is always going to be related to the child key, you can
already always get this data via multiget.

If you use a client which allows storage/fetch by 'master' key, you can
force both keys to always be on the same server. Then you always use a
multiget to fetch them back, which does one roundtrip.

libmemcached and Cache::Memcached support the fetch-by-master stuff.

-Dormando

cytown

unread,
Nov 6, 2008, 12:51:57 AM11/6/08
to memcached
You must delete key directly.

I suggest you make global content separately cache, and make unique
cache for each content.

Memcache taglibs have a cache admin servlet, you can set it in
web.xml, and view the cache list. But when release, delete it.
> > > > I'm not familiar with the memcachedtaglib, but generally you cannot
> > > delete
> > > > groups of keys from memcached without knowing the exact key name. This is
> > > a
> > > > very common problem because you don't always know exactly what keys you
> > > have
> > > > created that belong to a certain group, you only know that you want to
> > > > invalidate the whole group.
>
> > > > We solve this in our products by doing a double fetch, we store a prefix
> > > > under the group name, and then all keys that belong to the group gets
> > > this
> > > > prefix prepended to them. If you then change the prefix for a group, you
> > > > invalidate all the keys in that group. I have absolutely no idea if you
> > > can
> > > > do this with thetaglib(I'm guessing not), but it could perhaps be
> > > > implemented as a feature of thetaglibitself?
>
> > > > /Henrik Schröder
>
> > > > On Fri, Sep 19, 2008 at 7:52 AM, vp <vijayetapa...@gmail.com> wrote:
>
> > > > > Hii,
>
> > > > > I am using the memcachedtaglib. most of the pages have pagination ie
Reply all
Reply to author
Forward
0 new messages