Page Speed Optimization Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
net_instaweb::HTTPCache::Callback Class Referenceabstract

#include "http_cache.h"

Inheritance diagram for net_instaweb::HTTPCache::Callback:

Public Member Functions

 Callback (const RequestContextPtr &request_ctx)
 Callback (const RequestContextPtr &request_ctx, RequestHeaders::Properties req_properties)
virtual void Done (FindResult find_result)=0
virtual bool IsCacheValid (const GoogleString &key, const ResponseHeaders &headers)
virtual bool IsFresh (const ResponseHeaders &headers)
virtual int64 OverrideCacheTtlMs (const GoogleString &key)
void ReportLatencyMs (int64 latency_ms)
virtual ResponseHeaders::VaryOption RespectVaryOnResources () const =0
HTTPValuehttp_value ()
ResponseHeadersresponse_headers ()
const ResponseHeadersresponse_headers () const
void set_response_headers (ResponseHeaders *headers)
HTTPValuefallback_http_value ()
const RequestContextPtrrequest_context ()
void set_is_background (bool is_background)
RequestHeaders::Properties req_properties () const

Detailed Description

Class to handle an asynchronous cache lookup response.

TODO(jmarantz): consider inheriting from AsyncFetch with an implementation of Write/Flush/HeadersComplete – we'd have to make Done take true/false so this would impact callers.

Constructor & Destructor Documentation

net_instaweb::HTTPCache::Callback::Callback ( const RequestContextPtr request_ctx)

The 1-arg constructor does not learn anything about the request, and thus pessimistically will assume it has cookies, invalidating any response that has vary:cookie. However it will optimistically assume there is no authorization requirement. So a request-aware call to ResponseHeaders::IsProxyCacheable (e.g. via the 2-arg Callback constructor) must be applied when needed.

net_instaweb::HTTPCache::Callback::Callback ( const RequestContextPtr request_ctx,
RequestHeaders::Properties  req_properties 

The 2-arg constructor can be used in situations where we are confident that the cookies and authorization in the request-headers are valid.

Member Function Documentation

HTTPValue* net_instaweb::HTTPCache::Callback::http_value ( )
TODO(jmarantz): specify the dataflow between http_value and response_headers.
virtual bool net_instaweb::HTTPCache::Callback::IsCacheValid ( const GoogleString key,
const ResponseHeaders headers 

A method that allows client Callbacks to apply invalidation checks. We first (in check whether the entry is expired using normal http semantics, and if it is not expired, then this check is called – thus callbacks can apply any further invalidation semantics it wants on otherwise valid entries. But there's no way for a callback to override when the HTTP semantics say the entry is expired.

See also OptionsAwareHTTPCacheCallback in rewrite_driver.h for an implementation you probably want to use.

Reimplemented in net_instaweb::OptionsAwareHTTPCacheCallback.

virtual bool net_instaweb::HTTPCache::Callback::IsFresh ( const ResponseHeaders headers)

A method that allows client Callbacks to check if the response in cache is fresh enough, in addition to it being valid. This is used while freshening resources to check that the response in cache is not only valid, but is also not going to expire anytime soon. Note that if the response in cache is valid but not fresh, the HTTPCache calls Callback::Done with find_result = kNotFound and fills in fallback_http_value() with the cached response.

virtual int64 net_instaweb::HTTPCache::Callback::OverrideCacheTtlMs ( const GoogleString key)

Overrides the cache ttl of the cached response with the given value. Note that this has no effect if the returned value is negative or less than the cache ttl of the stored value.

Reimplemented in net_instaweb::OptionsAwareHTTPCacheCallback.

void net_instaweb::HTTPCache::Callback::ReportLatencyMs ( int64  latency_ms)

Called upon completion of a cache lookup trigged by HTTPCache::Find by the HTTPCache code with the latency in milliseconds. Will invoke ReportLatencyMsImpl for non-background fetches in order for system implementations, like RequestTimingInfo, to record the cache latency. Can be called multiple times for various levels of cache.

virtual ResponseHeaders::VaryOption net_instaweb::HTTPCache::Callback::RespectVaryOnResources ( ) const
pure virtual

Determines whether this Get request was made in the context where arbitrary Vary headers should be respected.

Note that Vary:Accept-Encoding is ignored at this level independent of this setting, and Vary:Cookie is always respected independent of this setting. Vary:Cookie prevents cacheing resources. For HTML, however, we can cache Vary:Cookie responses as long as there is no cookie in the request.

Implemented in net_instaweb::OptionsAwareHTTPCacheCallback.

The documentation for this class was generated from the following file: