Simplify version endpoint caching to indefinite cache

Since containers restart on content changes, remove TTL-based cache expiration
and cache version information indefinitely. This provides maximum performance
benefit while maintaining correctness.

- Remove timestamp-based cache expiration logic
- Cache version info indefinitely until container restart
- Simplify caching function by removing TTL complexity
- Maintain optimized git log file reading
This commit is contained in:
Oliver Falk
2025-10-17 14:14:14 +02:00
parent 8a1ccb1e0f
commit ba4c587e5c

View File

@@ -845,11 +845,9 @@ class StatsView(TemplateView, JsonResponse):
return JsonResponse(retval) return JsonResponse(retval)
# Thread-safe version cache with timestamp # Thread-safe version cache - cached indefinitely since container restarts on changes
_version_cache = None _version_cache = None
_version_cache_timestamp = None
_version_cache_lock = threading.Lock() _version_cache_lock = threading.Lock()
_VERSION_CACHE_TTL = 300 # 5 minutes cache TTL
def _get_git_info_from_files(): def _get_git_info_from_files():
@@ -957,33 +955,22 @@ def _get_git_info_from_files():
def _get_cached_version_info(): def _get_cached_version_info():
""" """
Get cached version information, loading it if not available or expired Get cached version information, loading it if not available
Since containers restart on content changes, cache indefinitely
""" """
global _version_cache, _version_cache_timestamp global _version_cache
import time
with _version_cache_lock: with _version_cache_lock:
current_time = time.time() if _version_cache is None:
# Check if cache is expired or doesn't exist
if (
_version_cache is None
or _version_cache_timestamp is None
or current_time - _version_cache_timestamp > _VERSION_CACHE_TTL
):
# Get version info from git files # Get version info from git files
_version_cache = _get_git_info_from_files() _version_cache = _get_git_info_from_files()
_version_cache_timestamp = current_time
# If that fails, return error but don't cache it for long # If that fails, return error
if _version_cache is None: if _version_cache is None:
_version_cache = { _version_cache = {
"error": "Unable to determine version - .git directory not found", "error": "Unable to determine version - .git directory not found",
"deployment_status": "unknown", "deployment_status": "unknown",
} }
# Set shorter TTL for error cases to allow retry
_version_cache_timestamp = current_time - _VERSION_CACHE_TTL + 30
return _version_cache return _version_cache