Code

Ticket #6086: rm_simple.diff

File rm_simple.diff, 2.4 KB (added by pbx, 6 years ago)

Sorry - original patch didn't include removal of simple.py

Line 
1Index: django/core/cache/backends/simple.py
2===================================================================
3--- django/core/cache/backends/simple.py        (revision 6803)
4+++ django/core/cache/backends/simple.py        (working copy)
5@@ -1,73 +0,0 @@
6-"Single-process in-memory cache backend."
7-
8-from django.core.cache.backends.base import BaseCache
9-import time
10-
11-class CacheClass(BaseCache):
12-    def __init__(self, host, params):
13-        BaseCache.__init__(self, params)
14-        self._cache = {}
15-        self._expire_info = {}
16-
17-        max_entries = params.get('max_entries', 300)
18-        try:
19-            self._max_entries = int(max_entries)
20-        except (ValueError, TypeError):
21-            self._max_entries = 300
22-
23-        cull_frequency = params.get('cull_frequency', 3)
24-        try:
25-            self._cull_frequency = int(cull_frequency)
26-        except (ValueError, TypeError):
27-            self._cull_frequency = 3
28-
29-    def add(self, key, value, timeout=None):
30-        if len(self._cache) >= self._max_entries:
31-            self._cull()
32-        if timeout is None:
33-            timeout = self.default_timeout
34-        if key not in self._cache.keys():
35-            self._cache[key] = value
36-            self._expire_info[key] = time.time() + timeout
37-
38-    def get(self, key, default=None):
39-        now = time.time()
40-        exp = self._expire_info.get(key)
41-        if exp is None:
42-            return default
43-        elif exp < now:
44-            del self._cache[key]
45-            del self._expire_info[key]
46-            return default
47-        else:
48-            return self._cache[key]
49-
50-    def set(self, key, value, timeout=None):
51-        if len(self._cache) >= self._max_entries:
52-            self._cull()
53-        if timeout is None:
54-            timeout = self.default_timeout
55-        self._cache[key] = value
56-        self._expire_info[key] = time.time() + timeout
57-
58-    def delete(self, key):
59-        try:
60-            del self._cache[key]
61-        except KeyError:
62-            pass
63-        try:
64-            del self._expire_info[key]
65-        except KeyError:
66-            pass
67-
68-    def has_key(self, key):
69-        return key in self._cache
70-
71-    def _cull(self):
72-        if self._cull_frequency == 0:
73-            self._cache.clear()
74-            self._expire_info.clear()
75-        else:
76-            doomed = [k for (i, k) in enumerate(self._cache) if i % self._cull_frequency == 0]
77-            for k in doomed:
78-                self.delete(k)