Skip to content

Commit 5b4450a

Browse files
authored
Use @lru_cache(maxsize=None) when appropriate (#1746)
For functions which do not take arguments, there is no need to limit the maximum size of the cache used by @lru_cache (since it will never have more than one entry). By using @lru_cache(maxsize=None), a simpler, faster cache implementation is used internally.
1 parent 36a0a75 commit 5b4450a

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

debug_toolbar/middleware.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def show_toolbar(request):
2222
return settings.DEBUG and request.META.get("REMOTE_ADDR") in settings.INTERNAL_IPS
2323

2424

25-
@lru_cache
25+
@lru_cache(maxsize=None)
2626
def get_show_toolbar():
2727
# If SHOW_TOOLBAR_CALLBACK is a string, which is the recommended
2828
# setup, resolve it to the corresponding callable.

debug_toolbar/settings.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
}
4646

4747

48-
@lru_cache
48+
@lru_cache(maxsize=None)
4949
def get_config():
5050
USER_CONFIG = getattr(settings, "DEBUG_TOOLBAR_CONFIG", {})
5151
CONFIG = CONFIG_DEFAULTS.copy()
@@ -70,7 +70,7 @@ def get_config():
7070
]
7171

7272

73-
@lru_cache
73+
@lru_cache(maxsize=None)
7474
def get_panels():
7575
try:
7676
PANELS = list(settings.DEBUG_TOOLBAR_PANELS)

debug_toolbar/toolbar.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def is_toolbar_request(cls, request):
166166
return resolver_match.namespaces and resolver_match.namespaces[-1] == APP_NAME
167167

168168
@staticmethod
169-
@lru_cache(maxsize=128)
169+
@lru_cache(maxsize=None)
170170
def get_observe_request():
171171
# If OBSERVE_REQUEST_CALLBACK is a string, which is the recommended
172172
# setup, resolve it to the corresponding callable.

0 commit comments

Comments
 (0)