-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclear_cache.py
More file actions
30 lines (23 loc) · 1.08 KB
/
clear_cache.py
File metadata and controls
30 lines (23 loc) · 1.08 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
import logging
from app import app
from hookwise.extensions import redis_client
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def clear_cw_cache() -> None:
with app.app_context():
# keys list removed as it was unused
# Also need to find wildcard keys for statuses, types, subtypes, items if possible
# Redis SCAN is better but for now let's try to list specific ones or flush all if acceptable?
# Flushing all might lose session data if stored in Redis? Flask-Session usually uses Redis.
# Let's stick to known keys and maybe use keys() pattern if needed.
# Pattern match for dynamic keys
try:
for key in redis_client.scan_iter("hookwise_cw_*"):
key_str = key.decode("utf-8")
logger.info(f"Deleting cache key: {key_str}")
redis_client.delete(key)
logger.info("ConnectWise API cache cleared successfully.")
except Exception as e:
logger.error(f"Error clearing cache: {e}")
if __name__ == "__main__":
clear_cw_cache()