mirror of
https://github.com/django-components/django-components.git
synced 2025-08-04 06:18:17 +00:00
refactor: fix error when template cache is set to 0 (#980)
This commit is contained in:
parent
58d4c78671
commit
fdfdc72ed2
3 changed files with 31 additions and 0 deletions
|
@ -1,5 +1,11 @@
|
|||
# Release notes
|
||||
|
||||
## v0.129
|
||||
|
||||
#### Fix
|
||||
|
||||
- Fix error when template cache setting (`template_cache_size`) is set to 0.
|
||||
|
||||
## v0.128
|
||||
|
||||
#### Feat
|
||||
|
|
|
@ -63,6 +63,10 @@ class LRUCache(Generic[T]):
|
|||
:param key: Key to insert or update.
|
||||
:param value: Value to associate with the key.
|
||||
"""
|
||||
# Noop if maxsize is set to 0
|
||||
if self.maxsize is not None and self.maxsize <= 0:
|
||||
return
|
||||
|
||||
if key in self.cache:
|
||||
node = self.cache[key]
|
||||
# Update the value
|
||||
|
|
|
@ -43,6 +43,27 @@ class CacheTests(TestCase):
|
|||
self.assertEqual(cache.get("e"), None)
|
||||
self.assertEqual(cache.get("f"), None)
|
||||
|
||||
def test_cache_maxsize_zero(self):
|
||||
cache = LRUCache[int](maxsize=0)
|
||||
|
||||
cache.set("a", 1)
|
||||
self.assertEqual(cache.get("a"), None)
|
||||
|
||||
cache.set("b", 2)
|
||||
cache.set("c", 3)
|
||||
self.assertEqual(cache.get("b"), None)
|
||||
self.assertEqual(cache.get("c"), None)
|
||||
|
||||
# Same with negative numbers
|
||||
cache = LRUCache[int](maxsize=-1)
|
||||
cache.set("a", 1)
|
||||
self.assertEqual(cache.get("a"), None)
|
||||
|
||||
cache.set("b", 2)
|
||||
cache.set("c", 3)
|
||||
self.assertEqual(cache.get("b"), None)
|
||||
self.assertEqual(cache.get("c"), None)
|
||||
|
||||
|
||||
class ComponentMediaCacheTests(TestCase):
|
||||
def setUp(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue