Page Speed Optimization Libraries
1.11.33.2
|
#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) |
Timer * | timer () const |
CacheInterface * | cache () |
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) |
Variable * | cache_time_us () |
Stats for the HTTP cache. | |
Variable * | cache_hits () |
Variable * | cache_misses () |
Variable * | cache_fallbacks () |
Variable * | cache_expirations () |
Variable * | cache_inserts () |
Variable * | cache_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 |
Implements HTTP caching semantics, including cache expiration and retention of the originally served cache headers.
|
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:.
respect_vary_on_resources |
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.
|
inline |
Sets how many levels the cache has. Affects reporting of statistics — we don't want them for lower levels of multi-level setups.
|
inline |
Sets the compression level of HTTP Cache. 9 being the most compression, -1 being the gzip default (6), and 0 being off.