promptguard.cache¶
- class promptguard.PromptCache(max_size=10000, ttl_seconds=3600)[source]¶
Bases:
objectIn-memory LRU cache for prompt analysis results.
Uses MD5 hash of the prompt text as the cache key. Entries are evicted in least-recently-used order when the cache reaches
max_size. An optional TTL causes stale entries to be discarded on read.- Parameters:
max_size (int) – Maximum number of entries to hold before evicting the LRU entry. Must be a positive integer. Defaults to 10 000.
ttl_seconds (int | None) – Optional time-to-live in seconds. Entries older than this value are treated as cache misses and silently removed. Pass
None(the default) to disable expiry.
- get(prompt)[source]¶
Return the cached
RiskScorefor prompt, orNoneon miss.A miss is returned when: * the prompt has never been cached, or * the cached entry has exceeded
ttl_seconds.