Dealing with cache expiration
This commit is contained in:
+17
-13
@@ -106,7 +106,7 @@ def main():
|
||||
json.dump(context_data, f, indent=4)
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# CACHE CREATION LOGIC
|
||||
# CACHE VALIDATION & CREATION LOGIC
|
||||
# ---------------------------------------------------------
|
||||
system_instruction = (
|
||||
"You are a hybrid data extraction tool. If a specific format or file format output is requested "
|
||||
@@ -128,6 +128,8 @@ def main():
|
||||
|
||||
if model_cache_info:
|
||||
cached_files_set = set(model_cache_info.get("cached_file_ids", []))
|
||||
|
||||
# Check 1: Have the files changed?
|
||||
if current_files_set != cached_files_set:
|
||||
print(f"File list changed. Destroying stale {args.model} cache to rebuild...")
|
||||
try:
|
||||
@@ -135,6 +137,20 @@ def main():
|
||||
except Exception as e:
|
||||
print(f"Warning: Could not delete stale cache. {e}", file=sys.stderr)
|
||||
rebuild_cache = True
|
||||
else:
|
||||
# Check 2: Does the cache still exist on the server?
|
||||
print(f"Verifying existing cache for {args.model}: {model_cache_info['cache_id']}...")
|
||||
try:
|
||||
client.caches.get(name=model_cache_info['cache_id'])
|
||||
print("Cache verified. Extending TTL by 60 minutes...")
|
||||
client.caches.update(
|
||||
name=model_cache_info['cache_id'],
|
||||
config=types.UpdateCachedContentConfig(ttl="3600s")
|
||||
)
|
||||
active_cache_id = model_cache_info['cache_id']
|
||||
except Exception as e:
|
||||
print(f"Cache expired or not found. Flagging for rebuild. ({e})")
|
||||
rebuild_cache = True
|
||||
else:
|
||||
rebuild_cache = True
|
||||
|
||||
@@ -167,18 +183,6 @@ def main():
|
||||
cache_too_small = True
|
||||
else:
|
||||
raise e
|
||||
|
||||
elif not cache_too_small and model_cache_info:
|
||||
active_cache_id = model_cache_info["cache_id"]
|
||||
print(f"Loading existing cache for {args.model}: {active_cache_id}")
|
||||
print("Extending cache TTL by 60 minutes...")
|
||||
try:
|
||||
client.caches.update(
|
||||
name=active_cache_id,
|
||||
config=types.UpdateCachedContentConfig(ttl="3600s")
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"Warning: Failed to update cache TTL. {e}")
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# GENERATION LOGIC (WITH HISTORY)
|
||||
|
||||
Reference in New Issue
Block a user