Cache Endpoint
The Cache API provides utilities for inspecting and managing Docura's in-memory document cache. These endpoints are useful for developers and admins who want to monitor cache usage, clear stored data, or maintain optimal system performance.
Example Cache Endpoint
A demo of the
Cache Endpoint component in action.Use the Cache API to check how many documents are cached, clear cache entries, or remove expired ones.
GET /cache/stats
POST /cache/clear
POST /cache/clear-expired
How to add
# Using the Cache API BASE_URL="https://docura-api.example.com" # Or run locally git clone https://github.com/msnabiel/Docura.git cd Docura pip install -r requirements.txt uvicorn app.main:app --reload --host 0.0.0.0 --port 8000 # BASE_URL="http://localhost:9000"
How to use
# Get cache statistics curl -X GET "$BASE_URL/cache/stats" \ -H "Accept: application/json" # Clear all cached documents curl -X POST "$BASE_URL/cache/clear" \ -H "Accept: application/json" # Clear expired cache entries (if applicable) curl -X POST "$BASE_URL/cache/clear-expired" \ -H "Accept: application/json"
📡 Endpoint Details
GET:
/cache/statsReturns a JSON object with current cache statistics, such as number of entries, size, and hit/miss counts.
POST:
/cache/clearClears all documents from the cache. Useful when invalidating stale data.
POST:
/cache/clear-expiredRemoves expired cache entries. If no expiry mechanism is configured, this returns a success message without clearing any entries.
📋 Response Examples
# GET /cache/stats
{
"total_entries": 42,
"total_size_kb": 512,
"hit_count": 120,
"miss_count": 15
}
# POST /cache/clear
{
"success": true,
"message": "All cache entries cleared"
}
# POST /cache/clear-expired
{
"success": true,
"cleared_entries": 0,
"message": "No cache expiry configured - no entries to clear"
}Note: Clearing the cache will remove all stored documents from memory. If the system depends on cached results for performance, be aware that subsequent queries may take longer until the cache is repopulated.