mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #18330 - Made cache culling 3rd party db backend friendly
This is Ian Kelly's patch from #15580 with minor modifications.
This commit is contained in:
14
django/core/cache/backends/db.py
vendored
14
django/core/cache/backends/db.py
vendored
@@ -167,17 +167,9 @@ class DatabaseCache(BaseDatabaseCache):
|
||||
num = cursor.fetchone()[0]
|
||||
if num > self._max_entries:
|
||||
cull_num = num / self._cull_frequency
|
||||
if connections[db].vendor == 'oracle':
|
||||
# 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(
|
||||
connections[db].ops.cache_key_culling_sql() % table,
|
||||
[cull_num])
|
||||
cursor.execute("DELETE FROM %s "
|
||||
"WHERE cache_key < %%s" % table,
|
||||
[cursor.fetchone()[0]])
|
||||
|
||||
Reference in New Issue
Block a user