Opened 17 years ago

Closed 17 years ago

#4831 closed (fixed)

Adding "add" support to the cache API

Reported by: crazyal Owned by: nobody
Component: Core (Cache system) Version: dev
Severity: Keywords: cache memcached sprintsept14
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The Django system has a "set" function for the cache backend which works with memcached which also has a "set" function.
But memcached also has an "add" function which the Django cache backend doesn't seem to support.

The "add" function becomes important with high traffic sites. If alot of requests are coming to the server and wanting to rebuild the cache, using "set" means each request will effectively try and set the cache which becomes a problem. The "add" function means it will only add the new cache if it hasn't already been added.

Attachments (1)

4831-1.diff (8.4 KB ) - added by Matt McClanahan <cardinal@…> 17 years ago.

Download all attachments as: .zip

Change History (6)

by Matt McClanahan <cardinal@…>, 17 years ago

Attachment: 4831-1.diff added

comment:1 by Matt McClanahan <cardinal@…>, 17 years ago

Has patch: set
Summary: Adding "add" support to memcached cache_backendAdding "add" support to the cache API
Triage Stage: UnreviewedDesign decision needed

One thing to note about this patch is that it exposes a bug in version 1.36 of the python-memcached client from tummy.com. The add method is missing a required argument that will need to be added if people wish to use add() with that memcached backend. Example patch:

--- /usr/src/python-memcached-1.36/build/lib/memcache.py        2007-06-07 03:30:39.000000000 -0700
+++ memcache.py 2007-07-11 03:32:16.000000000 -0700
@@ -365,7 +365,7 @@
             server.mark_dead(msg[1])
             return None
 
-    def add(self, key, val, time=0):
+    def add(self, key, val, time=0, min_compress_len=0):
         '''
         Add new key with value.
 
@@ -374,7 +374,7 @@
         @return: Nonzero on success.
         @rtype: int
         '''
-        return self._set("add", key, val, time)
+        return self._set("add", key, val, time, min_compress_len)
     def replace(self, key, val, time=0, min_compress_len=0):
         '''Replace existing key with value.

in reply to:  1 comment:2 by Matt McClanahan <cardinal@…>, 17 years ago

Replying to Matt McClanahan <cardinal@dodds.net>:

One thing to note about this patch is that it exposes a bug in version 1.36 of the python-memcached client from tummy.com. The add method is missing a required argument that will need to be added if people wish to use add() with that memcached backend. Example patch:

This has been fixed in 1.37.

comment:3 by Matt McClanahan, 17 years ago

Triage Stage: Design decision neededReady for checkin

comment:4 by Matt McClanahan, 17 years ago

Keywords: sprintsept14 added

comment:5 by Malcolm Tredinnick, 17 years ago

Resolution: fixed
Status: newclosed

(In [6572]) Fixed #4831 -- Added an "add" cache key method, for parity with memcached's
API. This works for all cache backends. Patch from Matt McClanahan.

Note: See TracTickets for help on using tickets.
Back to Top