Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
net_instaweb::HTTPCache Class Reference

#include "http_cache.h"

Classes

class  Callback
 
struct  FindResult
 When a lookup is done in the HTTP Cache, it returns one of these values. More...
 

Public Types

enum  FindResultClassification { kFound, kNotFound, kRecentFailure }
 

Public Member Functions

 HTTPCache (CacheInterface *cache, Timer *timer, Hasher *hasher, Statistics *stats)
 Does not take ownership of any inputs.
 
void set_hasher (Hasher *hasher)
 
void SetIgnoreFailurePuts ()
 Makes the cache ignore put requests that do not record successes.
 
void Find (const GoogleString &key, const GoogleString &fragment, MessageHandler *handler, Callback *callback)
 
void Put (const GoogleString &key, const GoogleString &fragment, RequestHeaders::Properties req_properties, const HttpOptions &http_options, HTTPValue *value, MessageHandler *handler)
 
void Put (const GoogleString &key, const GoogleString &fragment, RequestHeaders::Properties req_properties, ResponseHeaders::VaryOption respect_vary_on_resources, ResponseHeaders *headers, const StringPiece &content, MessageHandler *handler)
 
void Delete (const GoogleString &key, const GoogleString &fragment)
 Deletes an element in the cache.
 
void set_force_caching (bool force)
 
bool force_caching () const
 
void set_disable_html_caching_on_https (bool x)
 
Timertimer () const
 
CacheInterfacecache ()
 
void RememberFailure (const GoogleString &key, const GoogleString &fragment, FetchResponseStatus the_failure, MessageHandler *handler)
 
bool IsCacheableContentLength (ResponseHeaders *headers) const
 
bool IsCacheableBodySize (int64 body_size) const
 
bool IsExpired (const ResponseHeaders &headers)
 
bool IsExpired (const ResponseHeaders &headers, int64 now_ms)
 
Variablecache_time_us ()
 Stats for the HTTP cache.
 
Variablecache_hits ()
 
Variablecache_misses ()
 
Variablecache_fallbacks ()
 
Variablecache_expirations ()
 
Variablecache_inserts ()
 
Variablecache_deletes ()
 
int failure_caching_ttl_sec (FetchResponseStatus kind) const
 
void set_failure_caching_ttl_sec (FetchResponseStatus kind, int ttl_sec)
 
int max_cacheable_response_content_length ()
 
void set_max_cacheable_response_content_length (int64 value)
 
void set_cache_levels (int levels)
 
int cache_levels () const
 
void SetCompressionLevel (int level)
 
int compression_level () const
 
GoogleString Name () const
 
GoogleString CompositeKey (StringPiece key, StringPiece fragment) const
 

Static Public Member Functions

static GoogleString FormatEtag (StringPiece hash)
 Function to format etags.
 
static void InitStats (Statistics *statistics)
 Initialize statistics variables for the cache.
 
static GoogleString FormatName (StringPiece cache)
 

Static Public Attributes

static const char kCacheTimeUs []
 Names of statistics variables: exported for tests.
 
static const char kCacheHits []
 
static const char kCacheMisses []
 
static const char kCacheBackendHits []
 
static const char kCacheBackendMisses []
 
static const char kCacheFallbacks []
 
static const char kCacheExpirations []
 
static const char kCacheInserts []
 
static const char kCacheDeletes []
 
static const char kEtagPrefix []
 The prefix used for Etags.
 

Friends

class HTTPCacheCallback
 

Detailed Description

Implements HTTP caching semantics, including cache expiration and retention of the originally served cache headers.

The cache is fragmented by the Host: header that the browser sends to the server to prevent cache poisoning. For example, if good.com and evil.com were to use the same shared hosting provider with a shared cache and no fragmentation, evil.com could put in a MapOriginDomain that would tell PageSpeed to fetch good.com resources from henchman.com. When the request came into PageSpeed via evil.com and the response referenced resources on good.com PageSpeed would fetch those resources from henchman.com and put them in the cache. If the cache were shared completely between good.com and evil.com, then PageSpeed would use these poisoned files when serving responses for good.com. To break this attack we put files into their own cache spaces, divided by Host: header.

Note that it's not enough to do this by virtual host: some hosting providers don't use separate vhosts for separate clients.

In some cases we don't want fragmentation by vhost, for example www.example.com and images.example.com would like to share a cache. In that case they can opt in to a shared cache by chosing their own fragment to use.

Member Function Documentation

GoogleString net_instaweb::HTTPCache::CompositeKey ( StringPiece  key,
StringPiece  fragment 
) const
inline

Return "version/fragment/key" if there's a fragment, otherwise just return "version/key".

void net_instaweb::HTTPCache::Find ( const GoogleString key,
const GoogleString fragment,
MessageHandler handler,
Callback callback 
)

Non-blocking Find. Calls callback when done. 'handler' must all stay valid until callback->Done() is called.

bool net_instaweb::HTTPCache::IsCacheableBodySize ( int64  body_size) const

Indicates if the response body is within the cacheable size limit. If the response headers do not have content length header, then the clients of HTTPCache must check if the received response body is of cacheable size before buffering them in memory.

bool net_instaweb::HTTPCache::IsCacheableContentLength ( ResponseHeaders headers) const

Indicates if the response is within the cacheable size limit. Clients of HTTPCache must check if they will be eventually able to cache their entries before buffering them in memory. If the content length header is not found then consider it as cacheable. This could be a chunked response.

bool net_instaweb::HTTPCache::IsExpired ( const ResponseHeaders headers)

Returns true if the resource is already at the point of expiration and would never be used if inserted into the cache. Otherwise, returns false.

Note that this does not check for general cacheability, only for expiration. You must call ResponseHeaders::IsProxyCacheable() if you want to also determine cacheability.

void net_instaweb::HTTPCache::Put ( const GoogleString key,
const GoogleString fragment,
RequestHeaders::Properties  req_properties,
const HttpOptions http_options,
HTTPValue value,
MessageHandler handler 
)

Note that Put takes a non-const pointer for HTTPValue so it can bump the reference count.

void net_instaweb::HTTPCache::Put ( const GoogleString key,
const GoogleString fragment,
RequestHeaders::Properties  req_properties,
ResponseHeaders::VaryOption  respect_vary_on_resources,
ResponseHeaders headers,
const StringPiece &  content,
MessageHandler handler 
)

Note that Put takes a non-const pointer for ResponseHeaders* so it can update the caching fields prior to storing. If you call this method, you must be certain that the outgoing request was not sent with Authorization:.

Parameters
respect_vary_on_resources
Todo:
TODO(sligocki): Remove this arg and use headers->http_options().
void net_instaweb::HTTPCache::RememberFailure ( const GoogleString key,
const GoogleString fragment,
FetchResponseStatus  the_failure,
MessageHandler handler 
)

Tell the HTTP Cache to remember that a fetch for particular key failed for some reason (such an error, or being uncacheable, or load shedding, etc). This will be cached according to remember_failure_policy(). This can save work for our backends and us.

void net_instaweb::HTTPCache::set_cache_levels ( int  levels)
inline

Sets how many levels the cache has. Affects reporting of statistics — we don't want them for lower levels of multi-level setups.

void net_instaweb::HTTPCache::SetCompressionLevel ( int  level)
inline

Sets the compression level of HTTP Cache. 9 being the most compression, -1 being the gzip default (6), and 0 being off.


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