Django

Code

Ticket #4831 (closed: fixed)

Opened 1 year ago

Last modified 10 months ago

Adding "add" support to the cache API

Reported by: crazyal Assigned to: nobody
Milestone: Component: Cache system
Version: SVN Keywords: cache memcached sprintsept14
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

4831-1.diff (8.4 kB) - added by Matt McClanahan <cardinal@dodds.net> on 07/11/07 17:35:29.

Change History

07/11/07 17:35:29 changed by Matt McClanahan <cardinal@dodds.net>

  • attachment 4831-1.diff added.

(follow-up: ↓ 2 ) 07/11/07 17:45:37 changed by Matt McClanahan <cardinal@dodds.net>

  • needs_better_patch changed.
  • needs_tests changed.
  • summary changed from Adding "add" support to memcached cache_backend to Adding "add" support to the cache API.
  • needs_docs changed.
  • has_patch set to 1.
  • stage changed from Unreviewed to Design 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 ) 08/10/07 21:23:00 changed by Matt McClanahan <cardinal@dodds.net>

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.

09/14/07 16:35:21 changed by mattmcc

  • stage changed from Design decision needed to Ready for checkin.

09/14/07 16:38:20 changed by mattmcc

  • keywords changed from cache memcached to cache memcached sprintsept14.

10/20/07 10:16:34 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(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?.


Add/Change #4831 (Adding "add" support to the cache API)




Change Properties
Action