Page Speed Optimization Libraries
1.7.30.4
|
#include "http_cache.h"
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, const GoogleString &fragment, MessageHandler *handler, Callback *callback) |
void | Put (const GoogleString &key, const GoogleString &fragment, RequestHeaders::Properties req_properties, ResponseHeaders::VaryOption respect_vary_on_resources, 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) |
virtual void | Delete (const GoogleString &key, const GoogleString &fragment) |
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) |
Timer * | timer () const |
virtual void | RememberNotCacheable (const GoogleString &key, const GoogleString &fragment, bool is_200_status_code, MessageHandler *handler) |
virtual void | RememberFetchFailed (const GoogleString &key, const GoogleString &fragment, MessageHandler *handler) |
virtual void | RememberFetchDropped (const GoogleString &key, const GoogleString &fragment, 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) |
Variable * | cache_time_us () |
Variable * | cache_hits () |
Variable * | cache_misses () |
Variable * | cache_fallbacks () |
Variable * | cache_expirations () |
Variable * | cache_inserts () |
Variable * | cache_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 GoogleString | CompositeKey (StringPiece key, StringPiece fragment) |
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. | |
Protected Member Functions | |
virtual void | PutInternal (const GoogleString &key, const GoogleString &fragment, int64 start_us, HTTPValue *value) |
Friends | |
class | HTTPCacheCallback |
class | WriteThroughHTTPCache |
Implements HTTP caching semantics, including cache expiration and retention of the originally served cache headers.
static GoogleString net_instaweb::HTTPCache::CompositeKey | ( | StringPiece | key, |
StringPiece | fragment | ||
) | [inline, static] |
Return "fragment/key" if there's a fragment, otherwise just return "key".
virtual void net_instaweb::HTTPCache::Find | ( | const GoogleString & | key, |
const GoogleString & | fragment, | ||
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::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, | ||
ResponseHeaders::VaryOption | respect_vary_on_resources, | ||
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:.
virtual void net_instaweb::HTTPCache::RememberFetchDropped | ( | const GoogleString & | key, |
const GoogleString & | fragment, | ||
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, |
const GoogleString & | fragment, | ||
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, |
const GoogleString & | fragment, | ||
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.