mirror of
https://git.linux-kernel.at/oliver/ivatar.git
synced 2025-11-11 10:46:24 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user