Code

Opened 7 years ago

Closed 7 years ago

#4831 closed (fixed)

Adding "add" support to the cache API

Reported by: crazyal Owned by: nobody
Component: Core (Cache system) Version: master
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: UI/UX:

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@…> 7 years ago.

Download all attachments as: .zip

Change History (6)

Changed 7 years ago by Matt McClanahan <cardinal@…>

comment:1 follow-up: Changed 7 years ago by Matt McClanahan <cardinal@…>

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Adding "add" support to memcached cache_backend to Adding "add" support to the cache API
  • Triage 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.

comment:2 in reply to: ↑ 1 Changed 7 years ago by Matt McClanahan <cardinal@…>

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 Changed 7 years ago by mattmcc

  • Triage Stage changed from Design decision needed to Ready for checkin

comment:4 Changed 7 years ago by mattmcc

  • Keywords sprintsept14 added

comment:5 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(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 Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.