Cache more forgejo-authentication source queries #172

Merged
christian-monch merged 2 commits from forgejo-authsource-caching into master 2025-11-26 18:50:35 +00:00
3 changed files with 16 additions and 3 deletions

View file

@ -1,3 +1,13 @@
# 5.2.1 (2025-11-26)
## Changes
- Improve caching in Forgejo authentication sources. All calls to a
Forgejo-authentication source are now cached with expiration duration
between one and five minutes. Authentication-related changes in Forgejo
instances might therefore become visible after up to five minutes.
# 5.2.0 (2025-10-29)
## New features

View file

@ -1 +1 @@
__version__ = '5.2.0'
__version__ = '5.2.1'

View file

@ -43,9 +43,9 @@ class MethodCache:
@staticmethod
def cache_temporary(
duration: int = 3600,
duration: int = 300,
) -> Callable:
""" Cache results for a given time (default: 3600 seconds) """
""" Cache results for a given time (default: 300 seconds) """
def decorator(func: Callable) -> Callable:
@wraps(func)
def wrapper(*args, **kwargs):
@ -132,6 +132,7 @@ class ForgejoAuthenticationSource(AuthenticationSource, MethodCache):
raise InvalidTokenError(msg)
return r.json()
@MethodCache.cache_temporary(duration=120)
def _get_user(
self,
token: str,
@ -145,6 +146,7 @@ class ForgejoAuthenticationSource(AuthenticationSource, MethodCache):
token,
)
@MethodCache.cache_temporary(duration=120)
def _get_teams_for_user(self, token: str) -> dict:
r = self._get_json_from_endpoint('user/teams', token)
return {team['name']: team for team in r}
@ -208,6 +210,7 @@ class ForgejoAuthenticationSource(AuthenticationSource, MethodCache):
)
return permissions
@MethodCache.cache_temporary(duration=60)
def authenticate(
self,
token: str,