@@ -129,6 +157,8 @@ class DatabaseCache(BaseDatabaseCache):
ifself._cull_frequency==0:
self.clear()
else:
# When USE_TZ is True, 'now' will be an aware datetime in UTC.
now=now.replace(tzinfo=None)
table=connections[db].ops.quote_name(self._table)
cursor.execute("DELETE FROM %s WHERE expires < %%s"%table,
[connections[db].ops.value_to_db_datetime(now)])
@@ -137,12 +167,19 @@ class DatabaseCache(BaseDatabaseCache):
ifnum>self._max_entries:
cull_num=num/self._cull_frequency
ifconnections[db].vendor=='oracle':
# Special case for Oracle because it doesn't support LIMIT + OFFSET
cursor.execute("SELECT cache_key FROM (SELECT ROW_NUMBER() OVER (ORDER BY cache_key) AS counter, cache_key FROM %s) WHERE counter > %%s AND COUNTER <= %%s"%table,[cull_num,cull_num+1])
# Oracle doesn't support LIMIT + OFFSET
cursor.execute("""SELECT cache_key FROM
(SELECT ROW_NUMBER() OVER (ORDER BY cache_key) AS counter, cache_key FROM %s)
WHERE counter > %%s AND COUNTER <= %%s"""%table,[cull_num,cull_num+1])
else:
# This isn't standard SQL, it's likely to break with some non officially supported databases
cursor.execute("SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s"%table,[cull_num])
cursor.execute("DELETE FROM %s WHERE cache_key < %%s"%table,[cursor.fetchone()[0]])