Page Speed Optimization Libraries  1.5.27.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Friends
net_instaweb::HTTPCache Class Reference

#include "http_cache.h"

Inheritance diagram for net_instaweb::HTTPCache:
net_instaweb::WriteThroughHTTPCache

List of all members.

Classes

class  Callback

Public Types

enum  FindResult { kFound, kNotFound, kRecentFetchFailed, kRecentFetchNotCacheable }
 When a lookup is done in the HTTP Cache, it returns one of these values. More...

Public Member Functions

 HTTPCache (CacheInterface *cache, Timer *timer, Hasher *hasher, Statistics *stats)
 Does not take ownership of any inputs.
virtual void set_hasher (Hasher *hasher)
virtual void SetIgnoreFailurePuts ()
 Makes the cache ignore put requests that do not record successes.
virtual void Find (const GoogleString &key, MessageHandler *handler, Callback *callback)
virtual void Put (const GoogleString &key, HTTPValue *value, MessageHandler *handler)
virtual void Put (const GoogleString &key, ResponseHeaders *headers, const StringPiece &content, MessageHandler *handler)
virtual void Delete (const GoogleString &key)
 Deletes an element in the cache.
virtual void set_force_caching (bool force)
bool force_caching () const
virtual void set_disable_html_caching_on_https (bool x)
Timertimer () const
virtual void RememberNotCacheable (const GoogleString &key, bool is_200_status_code, MessageHandler *handler)
virtual void RememberFetchFailed (const GoogleString &key, MessageHandler *handler)
virtual void RememberFetchDropped (const GoogleString &key, MessageHandler *handler)
bool IsCacheableContentLength (ResponseHeaders *headers) const
bool IsCacheableBodySize (int64 body_size) const
bool IsAlreadyExpired (const RequestHeaders *request_headers, const ResponseHeaders &headers)
Variablecache_time_us ()
Variablecache_hits ()
Variablecache_misses ()
Variablecache_fallbacks ()
Variablecache_expirations ()
Variablecache_inserts ()
Variablecache_deletes ()
int64 remember_not_cacheable_ttl_seconds ()
virtual void set_remember_not_cacheable_ttl_seconds (int64 value)
int64 remember_fetch_failed_ttl_seconds ()
virtual void set_remember_fetch_failed_ttl_seconds (int64 value)
int64 remember_fetch_dropped_ttl_seconds ()
virtual void set_remember_fetch_dropped_ttl_seconds (int64 value)
int max_cacheable_response_content_length ()
virtual void set_max_cacheable_response_content_length (int64 value)
virtual GoogleString Name () 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 kCacheFallbacks []
static const char kCacheExpirations []
static const char kCacheInserts []
static const char kCacheDeletes []
static const char kEtagPrefix []
 The prefix used for Etags.

Protected Member Functions

virtual void PutInternal (const GoogleString &key, int64 start_us, HTTPValue *value)

Friends

class HTTPCacheCallback
class WriteThroughHTTPCache

Detailed Description

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


Member Enumeration Documentation

When a lookup is done in the HTTP Cache, it returns one of these values.

Enumerator:
kRecentFetchFailed 

Helps avoid frequent refetching of resources which have error status codes or are not cacheable.


Member Function Documentation

virtual void net_instaweb::HTTPCache::Find ( const GoogleString &  key,
MessageHandler handler,
Callback callback 
) [virtual]

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

Reimplemented in net_instaweb::WriteThroughHTTPCache.

bool net_instaweb::HTTPCache::IsAlreadyExpired ( const RequestHeaders request_headers,
const ResponseHeaders headers 
)

Returns true if the resource is already at the point of expiration (or not cacheable by us), and would never be used if inserted into the cache. Otherwise, returns false. If the entry was rejected because of expiration but would otherwise have been cacheable, this also increments the cache expirations statistic.

request_headers is used to check for resources requested with authorization. It is OK to pass NULL if you're certain that the fetch was done without authorization headers.

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.

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.

virtual void net_instaweb::HTTPCache::Put ( const GoogleString &  key,
HTTPValue value,
MessageHandler handler 
) [virtual]

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

virtual void net_instaweb::HTTPCache::Put ( const GoogleString &  key,
ResponseHeaders headers,
const StringPiece &  content,
MessageHandler handler 
) [virtual]

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:.

virtual void net_instaweb::HTTPCache::RememberFetchDropped ( const GoogleString &  key,
MessageHandler handler 
) [virtual]

Tell the HTTP Cache to remember that we had to give up on doing a background fetch due to load. This will remember it for remember_fetch_load_shed_ttl_seconds_.

Reimplemented in net_instaweb::WriteThroughHTTPCache.

virtual void net_instaweb::HTTPCache::RememberFetchFailed ( const GoogleString &  key,
MessageHandler handler 
) [virtual]

Tell the HTTP Cache to remember that a particular key is not cacheable because the associated URL failing Fetch.

The not-cacheable setting will be 'remembered' for remember_fetch_failed_ttl_seconds_.

Reimplemented in net_instaweb::WriteThroughHTTPCache.

virtual void net_instaweb::HTTPCache::RememberNotCacheable ( const GoogleString &  key,
bool  is_200_status_code,
MessageHandler handler 
) [virtual]

Tell the HTTP Cache to remember that a particular key is not cacheable because the URL was marked with Cache-Control 'nocache' or Cache-Control 'private'. We would like to avoid DOSing the origin server or spinning our own wheels trying to re-fetch this resource. The not-cacheable setting will be 'remembered' for remember_not_cacheable_ttl_seconds_. Note that we remember whether the response was originally a "200 OK" so that we can check if the cache TTL can be overridden.

Reimplemented in net_instaweb::WriteThroughHTTPCache.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines