Memcached and two dimensional array
Chris Hondl
chris at imvu.com
Wed Jun 28 22:38:54 UTC 2006
This problem sounds similar to a problem we've solved with our database
query cache. We have many distinct database queries that we cache about a
particular entity (user, product, etc.), and we want to flush all of the
queries when the underlying data changes.
We've solved this problem by wrapping the memcache interface with an
extension api to support what we call "cache-class". The api supports
assigning any memcache key to a cache-class when get/set/add is called. The
api also has a function to flush all the keys associated with a
cache-class.
This is implemented at the cost of 0-2 extra memcache accesses per operation
and requires no chance to the memcache server. The extra accesses are used
to maintain a version number associated with each cache-class. The flush
call simply increments the version number, and the wrapped get call ignores
any data with an old version number.
We've had this in production for over two months. Our implementation is in
PHP and is pretty self-contained. Be glad to share with anyone interested.
Chris
--
http://avatars.imvu.com/chris
On 6/28/06, NTPT <NTPT at seznam.cz> wrote:
>
> Memcached and two dimensional array
>
>
> Hi.
>
> I have folowing situation in my project. I have "user data" identified by
> "user_id" and object data identified by "object_id"
>
> Now i need to render data of the object identified by object_id with
> settings stored in "user data". This process add a lot of overhead, so it
> need to be chached with memcached . So i construct key string like this in
> PHP $key = user_id . "_" . object_id It can cleany lidentify rendered
> data, it is fine.
>
>
> But "user data" and "object data" are changing quite fast. So i need a
> way to delete all data that are cached for some user, if user data are
> changed, and all rendered instance of certain object if the object is
> changed.
>
> Like in two dimensional array deleting a whole row or a whole column. Is
> it possible with memcache ?
>
> For now, it seems that only way to do is a flush a single key (with is
> insufficient) or flush entire cache with is too much....
>
>
> Thanx for help.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/memcached/attachments/20060628/feaeff68/attachment-0001.html
More information about the memcached
mailing list