From ba4c587e5c37d33d1ac98e60ae20167857f3e4f7 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Fri, 17 Oct 2025 14:14:14 +0200 Subject: [PATCH] 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 --- ivatar/views.py | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/ivatar/views.py b/ivatar/views.py index 323fdcf..4bbf795 100644 --- a/ivatar/views.py +++ b/ivatar/views.py @@ -845,11 +845,9 @@ class StatsView(TemplateView, JsonResponse): 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_timestamp = None _version_cache_lock = threading.Lock() -_VERSION_CACHE_TTL = 300 # 5 minutes cache TTL def _get_git_info_from_files(): @@ -957,33 +955,22 @@ def _get_git_info_from_files(): 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 - import time + global _version_cache with _version_cache_lock: - current_time = time.time() - - # 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 - ): - + if _version_cache is None: # Get version info from git 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: _version_cache = { "error": "Unable to determine version - .git directory not found", "deployment_status": "unknown", } - # Set shorter TTL for error cases to allow retry - _version_cache_timestamp = current_time - _VERSION_CACHE_TTL + 30 return _version_cache