Skip to content

Commit

Permalink
Use @lru_cache(maxsize=None) when appropriate (#1746)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
living180 committed Mar 6, 2023
1 parent 36a0a75 commit 5b4450a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion debug_toolbar/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def show_toolbar(request):
return settings.DEBUG and request.META.get("REMOTE_ADDR") in settings.INTERNAL_IPS


@lru_cache
@lru_cache(maxsize=None)
def get_show_toolbar():
# If SHOW_TOOLBAR_CALLBACK is a string, which is the recommended
# setup, resolve it to the corresponding callable.
Expand Down
4 changes: 2 additions & 2 deletions debug_toolbar/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
}


@lru_cache
@lru_cache(maxsize=None)
def get_config():
USER_CONFIG = getattr(settings, "DEBUG_TOOLBAR_CONFIG", {})
CONFIG = CONFIG_DEFAULTS.copy()
Expand All @@ -70,7 +70,7 @@ def get_config():
]


@lru_cache
@lru_cache(maxsize=None)
def get_panels():
try:
PANELS = list(settings.DEBUG_TOOLBAR_PANELS)
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def is_toolbar_request(cls, request):
return resolver_match.namespaces and resolver_match.namespaces[-1] == APP_NAME

@staticmethod
@lru_cache(maxsize=128)
@lru_cache(maxsize=None)
def get_observe_request():
# If OBSERVE_REQUEST_CALLBACK is a string, which is the recommended
# setup, resolve it to the corresponding callable.
Expand Down

0 comments on commit 5b4450a

Please sign in to comment.