A cache key decides which requests your application considers interchangeable. In an AI system, similar wording is not enough. The right answer can depend on the account, permission set, model configuration, source version and time of the request.
Start with the reuse boundary
Decide what is being reused: a public answer, a private result, a document transformation or a browser procedure. Each has a different boundary. A public definition may be shared widely; an invoice result should remain scoped to the authorized account.
Write down the fields that can change the result. Include an explicit version for the procedure or prompt when a change could alter behavior. If you cannot explain why two requests may share a value, keep them separate.
Canonicalize carefully
Normalize only differences that are irrelevant to the task. Sorting JSON object keys may be appropriate for a structured request, while lowercasing a case-sensitive identifier can change its meaning. Removing a URL query can collapse two different resources into one.
Test pairs that should match and pairs that must not match. Include two users with identical questions, changed permissions, a new source version and a different operation. A successful cache lookup is not evidence that your equivalence rule is correct.
Keep secrets out of key labels
Do not put raw credentials, personal text or private document contents into human-readable keys or logs. An opaque identifier can reduce accidental exposure, but a plain hash is not encryption and does not replace access control.
Store values behind an authorization boundary and recheck access when serving them. If permissions change after a value is cached, a matching key must not bypass the new policy. Consider whether backups, diagnostics and invalidation tools expose the same data.
Plan for change and deletion
Give entries a version and an expiry strategy. Track why an entry was invalidated so a rising miss rate can be diagnosed. When source data is deleted, consider cached values and derived results rather than deleting only the primary record.
For browser automation, include the relevant site and scope, then validate current state before using a saved action. Frugent separates reusable execution knowledge from fresh task values; callers still need suitable account boundaries and permission checks. A faster wrong-account result is a serious failure, not a cache optimization.
A key design to review
For a private document transformation, candidate dimensions are tenant ID, document ID, source revision, operation version, model configuration and an access-policy version where relevant. Treat this as a checklist, not a universal key. Hash or encode the structured tuple consistently, but authorize the current caller separately before returning the cached value. Test that a different tenant, revoked access or changed source revision cannot obtain a stale private result.
Sign in ↗