-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache_manager.py
More file actions
70 lines (55 loc) · 2.45 KB
/
Copy pathcache_manager.py
File metadata and controls
70 lines (55 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
"""
Cache Management Utility
Manual cache refresh for database updates
"""
import os
import sys
import asyncio
from dotenv import load_dotenv
from chatbot_refactored import ChatBot
def main():
"""Main function for cache management"""
load_dotenv()
print("🔄 Cache Management Utility")
print("=" * 40)
try:
chatbot = ChatBot(groq_key=os.environ.get('GROQ_API_KEY'))
if not hasattr(chatbot.database_search, 'redis') or not chatbot.database_search.redis_available:
print("❌ Redis not available - cache management disabled")
return
print("Available commands:")
print("1. refresh - Force refresh all cache")
print("2. clear - Clear all cache entries")
print("3. stats - Show cache statistics")
print("4. invalidate <query> - Invalidate specific query cache")
print("5. invalidate-grade <grade> - Invalidate grade-specific cache")
if len(sys.argv) < 2:
print("\nUsage: python cache_manager.py <command> [args]")
return
command = sys.argv[1].lower()
if command == "refresh":
result = chatbot.database_search.force_cache_refresh()
print(f"✅ Cache refresh: {'Success' if result else 'Failed'}")
elif command == "clear":
result = chatbot.database_search.clear_cache()
print(f"✅ Cache clear: {'Success' if result else 'Failed'}")
elif command == "stats":
stats = chatbot.database_search.get_cache_stats()
print(f"📊 Cache Statistics:")
for key, value in stats.items():
print(f" {key}: {value}")
elif command == "invalidate" and len(sys.argv) > 2:
query = sys.argv[2]
result = chatbot.database_search.invalidate_query_cache(query)
print(f"✅ Query cache invalidation: {'Success' if result else 'Failed'}")
elif command == "invalidate-grade" and len(sys.argv) > 2:
grade = sys.argv[2]
result = chatbot.database_search.invalidate_grade_cache(grade)
print(f"✅ Grade cache invalidation: {'Success' if result else 'Failed'}")
else:
print(f"❌ Unknown command: {command}")
except Exception as e:
print(f"❌ Error: {e}")
if __name__ == "__main__":
main()