1. import os
  2. import hashlib
  3. import json
  4. def invalidate_cache(api_key, endpoint, cache_file="api_cache.json"):
  5. """
  6. Invalidates the cache for a specific API endpoint.
  7. For development use only.
  8. """
  9. try:
  10. with open(cache_file, 'r') as f:
  11. cache = json.load(f)
  12. except FileNotFoundError:
  13. cache = {}
  14. cache_key = f"{api_key}:{endpoint}"
  15. if cache_key in cache:
  16. del cache[cache_key]
  17. print(f"Invalidated cache for {endpoint} using key {cache_key}")
  18. else:
  19. print(f"No cache found for {endpoint} using key {cache_key}")
  20. with open(cache_file, 'w') as f:
  21. json.dump(cache, f, indent=4)
  22. if __name__ == '__main__':
  23. # Example usage for development
  24. api_key = "dev_api_key" # Replace with your development API key
  25. endpoint = "/some/api/endpoint" # Replace with the specific endpoint.
  26. invalidate_cache(api_key, endpoint)

Add your comment