Fixed a bug in the db cache backend introduced in [6572].
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6589 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
0a4e4d5993
commit
ef454b8a14
|
@ -24,9 +24,6 @@ class CacheClass(BaseCache):
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
self._cull_frequency = 3
|
self._cull_frequency = 3
|
||||||
|
|
||||||
def add(self, key, value, timeout=None):
|
|
||||||
return self._base_set('add', key, value, timeout)
|
|
||||||
|
|
||||||
def get(self, key, default=None):
|
def get(self, key, default=None):
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
cursor.execute("SELECT cache_key, value, expires FROM %s WHERE cache_key = %%s" % self._table, [key])
|
cursor.execute("SELECT cache_key, value, expires FROM %s WHERE cache_key = %%s" % self._table, [key])
|
||||||
|
@ -43,6 +40,9 @@ class CacheClass(BaseCache):
|
||||||
def set(self, key, value, timeout=None):
|
def set(self, key, value, timeout=None):
|
||||||
return self._base_set('set', key, value, timeout)
|
return self._base_set('set', key, value, timeout)
|
||||||
|
|
||||||
|
def add(self, key, value, timeout=None):
|
||||||
|
return self._base_set('add', key, value, timeout)
|
||||||
|
|
||||||
def _base_set(self, mode, key, value, timeout=None):
|
def _base_set(self, mode, key, value, timeout=None):
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
timeout = self.default_timeout
|
timeout = self.default_timeout
|
||||||
|
@ -59,7 +59,6 @@ class CacheClass(BaseCache):
|
||||||
if mode == 'set' and cursor.fetchone():
|
if mode == 'set' and cursor.fetchone():
|
||||||
cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % self._table, [encoded, str(exp), key])
|
cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % self._table, [encoded, str(exp), key])
|
||||||
else:
|
else:
|
||||||
if mode == 'add':
|
|
||||||
cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % self._table, [key, encoded, str(exp)])
|
cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % self._table, [key, encoded, str(exp)])
|
||||||
except DatabaseError:
|
except DatabaseError:
|
||||||
# To be threadsafe, updates/inserts are allowed to fail silently
|
# To be threadsafe, updates/inserts are allowed to fail silently
|
||||||
|
|
Loading…
Reference in New Issue