Fixed #11483 -- Modified db cache backend to use db backend functions for date conversion, avoiding problems under Jython. Thanks to Leo Soto for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12411 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
ab828da2b9
commit
02d40b93f8
|
@ -60,9 +60,11 @@ class CacheClass(BaseCache):
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
if result and (mode == 'set' or
|
if result and (mode == 'set' or
|
||||||
(mode == 'add' and result[1] < now)):
|
(mode == 'add' and result[1] < now)):
|
||||||
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, connection.ops.value_to_db_datetime(exp), key])
|
||||||
else:
|
else:
|
||||||
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, connection.ops.value_to_db_datetime(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
|
||||||
transaction.rollback_unless_managed()
|
transaction.rollback_unless_managed()
|
||||||
|
@ -79,14 +81,16 @@ class CacheClass(BaseCache):
|
||||||
def has_key(self, key):
|
def has_key(self, key):
|
||||||
now = datetime.now().replace(microsecond=0)
|
now = datetime.now().replace(microsecond=0)
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
cursor.execute("SELECT cache_key FROM %s WHERE cache_key = %%s and expires > %%s" % self._table, [key, now])
|
cursor.execute("SELECT cache_key FROM %s WHERE cache_key = %%s and expires > %%s" % self._table,
|
||||||
|
[key, connection.ops.value_to_db_datetime(now)])
|
||||||
return cursor.fetchone() is not None
|
return cursor.fetchone() is not None
|
||||||
|
|
||||||
def _cull(self, cursor, now):
|
def _cull(self, cursor, now):
|
||||||
if self._cull_frequency == 0:
|
if self._cull_frequency == 0:
|
||||||
self.clear()
|
self.clear()
|
||||||
else:
|
else:
|
||||||
cursor.execute("DELETE FROM %s WHERE expires < %%s" % self._table, [str(now)])
|
cursor.execute("DELETE FROM %s WHERE expires < %%s" % self._table,
|
||||||
|
[connection.ops.value_to_db_datetime(now)])
|
||||||
cursor.execute("SELECT COUNT(*) FROM %s" % self._table)
|
cursor.execute("SELECT COUNT(*) FROM %s" % self._table)
|
||||||
num = cursor.fetchone()[0]
|
num = cursor.fetchone()[0]
|
||||||
if num > self._max_entries:
|
if num > self._max_entries:
|
||||||
|
|
Loading…
Reference in New Issue