private Duration calculateFreshnessLifetime(final ResponseCacheControl cacheControl, final Instant responseDate, final Instant responseExpires) {

        if (cacheControl.isUndefined()) {
            // If no cache-control header is present, assume no caching directives and return a default value
            return DEFAULT_FRESHNESS_DURATION; // 5 minutes
        }

        // Check if s-maxage is present and use its value if it is
        if (cacheControl.getSharedMaxAge() != -1) {
            return Duration.ofSeconds(cacheControl.getSharedMaxAge());
        } else if (cacheControl.getMaxAge() != -1) {
            return Duration.ofSeconds(cacheControl.getMaxAge());
        }

        if (responseDate != null && responseExpires != null) {
            return Duration.ofSeconds(responseExpires.getEpochSecond() - responseDate.getEpochSecond());
        }

        // If none of the above conditions are met, a heuristic freshness lifetime might be applicable
        return DEFAULT_FRESHNESS_DURATION; // 5 minutes
    }
Calculates the freshness lifetime of a response, based on the headers in the response.
<p>
This method follows the algorithm for calculating the freshness lifetime.
The freshness lifetime represents the time interval in seconds during which the response can be served without
being considered stale. The freshness lifetime calculation takes into account the s-maxage, max-age, Expires, and
Date headers as follows:
<ul>
<li>If the s-maxage directive is present in the Cache-Control header of the response, its value is used as the
freshness lifetime for shared caches, which typically serve multiple users or clients.</li>
<li>If the max-age directive is present in the Cache-Control header of the response, its value is used as the
freshness lifetime for private caches, which serve a single user or client.</li>
<li>If the Expires header is present in the response, its value is used as the expiration time of the response.
The freshness lifetime is calculated as the difference between the expiration time and the time specified in the
Date header of the response.</li>
<li>If none of the above headers are present or if the calculated freshness lifetime is invalid, a default value of
5 minutes is returned.</li>
</ul>

<p>
Note that caching is a complex topic and cache control directives may interact with each other in non-trivial ways.
This method provides a basic implementation of the freshness lifetime calculation algorithm and may not be suitable
for all use cases. Developers should consult the HTTP caching specifications for more information and consider
implementing additional caching mechanisms as needed.
</p>
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseCachingPolicy.java