Shared caches such as CDNs and reverse proxies must decide whether a response may be stored and reused without exposing private data or serving it beyond its freshness lifetime.
Design a stateless SharedHttpCachePolicy class:
SharedHttpCachePolicy() creates an evaluator.String evaluate(String method, int status, String cacheControl, int ageSeconds, boolean hasAuthorization) returns one of "BYPASS", "FRESH", "REVALIDATE", or "STALE".Use this deliberately scoped policy model:
GET and HEAD are eligible, compared case-insensitively.Cache-Control directives case-insensitively and ignore unknown directives.no-store or private returns "BYPASS".hasAuthorization is true, the response requires public or s-maxage to proceed.200, 203, 204, 206, 300, 301, 404, 405, 410, 414, and 501. Any other status requires public.s-maxage=N when present; otherwise use max-age=N. If neither exists, return "BYPASS".no-cache returns "REVALIDATE" after the response passes the preceding checks."FRESH" when ageSeconds < lifetime, or "STALE" when ageSeconds >= lifetime.This exercise does not implement heuristic freshness, validators, stale-while-revalidate, or request directives.
Input:
Output:
Explanation: Freshness uses a strict comparison. At age 60, the 60-second lifetime has ended.
Input:
Output:
Explanation: Shared-cache privacy overrides freshness. no-cache differs from no-store: it allows storage but requires validation. The shared cache uses s-maxage=30, not max-age=120.
method contains ASCII letters.100 <= status <= 599cacheControl is a comma-separated list of supported or unknown token directives.max-age and s-maxage values, when present, are integers in [0, 10^9] without quotes.0 <= ageSeconds <= 10^910^4 calls are made to evaluate.| Call | Returns |
|---|---|
| new SharedHttpCachePolicy() | null |
| evaluate("GET", 200, "public, max-age=60", 30, false) | "FRESH" |
| evaluate("GET", 200, "public, max-age=60", 60, false) | "STALE" |
The response can be served while age is strictly below 60 seconds. At the exact freshness boundary it is stale.
Run checks these cases. Submit also runs a larger hidden set.

