diff -r d578c187d733 django/core/cache/backends/base.py
a
|
b
|
|
22 | 22 | timeout = 300 |
23 | 23 | self.default_timeout = timeout |
24 | 24 | |
| 25 | max_entries = params.get('max_entries', 300) |
| 26 | try: |
| 27 | self._max_entries = int(max_entries) |
| 28 | except (ValueError, TypeError): |
| 29 | self._max_entries = 300 |
| 30 | |
| 31 | cull_frequency = params.get('cull_frequency', 3) |
| 32 | try: |
| 33 | self._cull_frequency = int(cull_frequency) |
| 34 | except (ValueError, TypeError): |
| 35 | self._cull_frequency = 3 |
| 36 | |
25 | 37 | def add(self, key, value, timeout=None): |
26 | 38 | """ |
27 | 39 | Set a value in the cache if the key does not already exist. If |
diff -r d578c187d733 django/core/cache/backends/db.py
a
|
b
|
|
25 | 25 | self.managed = True |
26 | 26 | self.proxy = False |
27 | 27 | |
28 | | class CacheClass(BaseCache): |
| 28 | class BaseDatabaseCacheClass(BaseCache): |
29 | 29 | def __init__(self, table, params): |
30 | 30 | BaseCache.__init__(self, params) |
31 | 31 | self._table = table |
… |
… |
|
34 | 34 | _meta = Options(table) |
35 | 35 | self.cache_model_class = CacheEntry |
36 | 36 | |
37 | | max_entries = params.get('max_entries', 300) |
38 | | try: |
39 | | self._max_entries = int(max_entries) |
40 | | except (ValueError, TypeError): |
41 | | self._max_entries = 300 |
42 | | cull_frequency = params.get('cull_frequency', 3) |
43 | | try: |
44 | | self._cull_frequency = int(cull_frequency) |
45 | | except (ValueError, TypeError): |
46 | | self._cull_frequency = 3 |
47 | | |
| 37 | class CacheClass(BaseDatabaseCacheClass): |
48 | 38 | def get(self, key, default=None): |
49 | 39 | self.validate_key(key) |
50 | 40 | db = router.db_for_read(self.cache_model_class) |
diff -r d578c187d733 django/core/cache/backends/filebased.py
a
|
b
|
|
14 | 14 | class CacheClass(BaseCache): |
15 | 15 | def __init__(self, dir, params): |
16 | 16 | BaseCache.__init__(self, params) |
17 | | |
18 | | max_entries = params.get('max_entries', 300) |
19 | | try: |
20 | | self._max_entries = int(max_entries) |
21 | | except (ValueError, TypeError): |
22 | | self._max_entries = 300 |
23 | | |
24 | | cull_frequency = params.get('cull_frequency', 3) |
25 | | try: |
26 | | self._cull_frequency = int(cull_frequency) |
27 | | except (ValueError, TypeError): |
28 | | self._cull_frequency = 3 |
29 | | |
30 | 17 | self._dir = dir |
31 | 18 | if not os.path.exists(self._dir): |
32 | 19 | self._createdir() |
diff -r d578c187d733 django/core/cache/backends/locmem.py
a
|
b
|
|
14 | 14 | BaseCache.__init__(self, params) |
15 | 15 | self._cache = {} |
16 | 16 | self._expire_info = {} |
17 | | |
18 | | max_entries = params.get('max_entries', 300) |
19 | | try: |
20 | | self._max_entries = int(max_entries) |
21 | | except (ValueError, TypeError): |
22 | | self._max_entries = 300 |
23 | | |
24 | | cull_frequency = params.get('cull_frequency', 3) |
25 | | try: |
26 | | self._cull_frequency = int(cull_frequency) |
27 | | except (ValueError, TypeError): |
28 | | self._cull_frequency = 3 |
29 | | |
30 | 17 | self._lock = RWLock() |
31 | 18 | |
32 | 19 | def add(self, key, value, timeout=None): |
diff -r d578c187d733 tests/regressiontests/cache/tests.py
a
|
b
|
|
410 | 410 | def test_cull(self): |
411 | 411 | self.perform_cull_test(50, 29) |
412 | 412 | |
| 413 | def test_zero_cull(self): |
| 414 | self.cache = get_cache('db://%s?max_entries=30&cull_frequency=0' % self._table_name) |
| 415 | self.perform_cull_test(50, 18) |
| 416 | |
413 | 417 | class LocMemCacheTests(unittest.TestCase, BaseCacheTests): |
414 | 418 | def setUp(self): |
415 | 419 | self.cache = get_cache('locmem://?max_entries=30') |
… |
… |
|
417 | 421 | def test_cull(self): |
418 | 422 | self.perform_cull_test(50, 29) |
419 | 423 | |
| 424 | def test_zero_cull(self): |
| 425 | self.cache = get_cache('locmem://?max_entries=30&cull_frequency=0') |
| 426 | self.perform_cull_test(50, 19) |
| 427 | |
420 | 428 | # memcached backend isn't guaranteed to be available. |
421 | 429 | # To check the memcached backend, the test settings file will |
422 | 430 | # need to contain a CACHE_BACKEND setting that points at |