Page Speed Optimization Libraries
1.8.31.2
|
Classes | |
class | AsyncCallback |
class | FreshenCallback |
Public Types | |
enum | HashHint { kOmitInputHash, kIncludeInputHash } |
enum | NotCacheablePolicy { kLoadEvenIfNotCacheable, kReportFailureIfNotCacheable } |
enum | FetchResponseStatus { kFetchStatusNotSet, kFetchStatusOK, kFetchStatusUncacheable, kFetchStatus4xxError, kFetchStatusDropped, kFetchStatusOther } |
This enumerates different states of the fetched response. | |
Public Member Functions | |
Resource (ServerContext *server_context, const ContentType *type) | |
ServerContext * | server_context () const |
Common methods across all deriviations. | |
virtual bool | IsValidAndCacheable () const |
bool | is_authorized_domain () |
void | set_is_authorized_domain (bool is_authorized) |
bool | IsSafeToRewrite (bool rewrite_uncacheable) const |
bool | loaded () const |
bool | HttpStatusOk () const |
void | LoadAsync (NotCacheablePolicy not_cacheable_policy, const RequestContextPtr &request_context, AsyncCallback *callback) |
virtual void | RefreshIfImminentlyExpiring () |
GoogleString | ContentsHash () const |
void | AddInputInfoToPartition (HashHint suggest_include_content_hash, int index, CachedResult *partition) |
virtual void | FillInPartitionInputInfo (HashHint suggest_include_content_hash, InputInfo *input) |
void | FillInPartitionInputInfoFromResponseHeaders (const ResponseHeaders &headers, InputInfo *input) |
int64 | CacheExpirationTimeMs () const |
StringPiece | contents () const |
ResponseHeaders * | response_headers () |
const ResponseHeaders * | response_headers () const |
const ContentType * | type () const |
virtual void | SetType (const ContentType *type) |
StringPiece | charset () const |
Note: this is empty if the header is not specified. | |
void | set_charset (StringPiece c) |
virtual GoogleString | url () const =0 |
Gets the absolute URL of the resource. | |
virtual GoogleString | cache_key () const |
void | DetermineContentType () |
bool | Link (HTTPValue *source, MessageHandler *handler) |
virtual void | Freshen (FreshenCallback *callback, MessageHandler *handler) |
void | LinkFallbackValue (HTTPValue *value) |
Links the stale fallback value that can be used in case a fetch fails. | |
void | set_is_background_fetch (bool x) |
bool | is_background_fetch () const |
FetchResponseStatus | fetch_response_status () |
void | set_fetch_response_status (FetchResponseStatus x) |
virtual bool | UseHttpCache () const =0 |
Protected Member Functions | |
REFCOUNT_FRIEND_DECLARATION (Resource) | |
virtual void | LoadAndCallback (NotCacheablePolicy not_cacheable_policy, const RequestContextPtr &request_context, AsyncCallback *callback)=0 |
void | set_enable_cache_purge (bool x) |
ResponseHeaders::VaryOption | respect_vary () const |
void | set_respect_vary (ResponseHeaders::VaryOption x) |
void | set_proactive_resource_freshening (bool x) |
void | set_disable_rewrite_on_no_transform (bool x) |
Protected Attributes | |
ServerContext * | server_context_ |
const ContentType * | type_ |
GoogleString | charset_ |
HTTPValue | value_ |
contains contents and meta-data | |
ResponseHeaders | response_headers_ |
HTTPValue | fallback_value_ |
Friends | |
class | ServerContext |
class | ReadAsyncHttpCacheCallback |
uses LoadAndCallback | |
class | RewriteDriver |
for ReadIfCachedWithStatus | |
class | UrlReadAsyncFetchCallback |
This enumerates possible follow-up behaviors when a requested resource was uncacheable.
void net_instaweb::Resource::AddInputInfoToPartition | ( | HashHint | suggest_include_content_hash, |
int | index, | ||
CachedResult * | partition | ||
) |
Adds a new InputInfo object representing this resource to CachedResult, assigning the index supplied.
virtual GoogleString net_instaweb::Resource::cache_key | ( | ) | const [inline, virtual] |
Gets the cache key for resource. This may be different from URL if the resource is e.g. UA-dependent.
Reimplemented in net_instaweb::CacheableResourceBase.
int64 net_instaweb::Resource::CacheExpirationTimeMs | ( | ) | const |
Returns 0 if resource is not cacheable.
GoogleString net_instaweb::Resource::ContentsHash | ( | ) | const |
Computes (with non-trivial cost) a hash of contents of a loaded resource. Precondition: IsValidAndCacheable(). Warning: this uses contents_hasher_ and not the primary hasher, unlike the hashes computed by OutputResource for naming purposes on writes.
Computes the content-type (and charset) based on response_headers and extension, and sets it via SetType.
virtual void net_instaweb::Resource::FillInPartitionInputInfo | ( | HashHint | suggest_include_content_hash, |
InputInfo * | input | ||
) | [virtual] |
Set CachedResult's input info used for expiration validation. If include_content_hash is kIncludeInputHash, and it makes sense for the Resource type to check if resource changed based by content hash (e.g. it would be pointless for data:), the hash of resource's contents should also be set on 'input'.
Default one sets resource type as CACHED and sets an expiration timestamp, last modified, date, and, if requested, content hash. If a derived class has a different criterion for validity, override this method.
Reimplemented in net_instaweb::DataUrlInputResource, and net_instaweb::FileInputResource.
virtual void net_instaweb::Resource::Freshen | ( | FreshenCallback * | callback, |
MessageHandler * | handler | ||
) | [virtual] |
Freshen a soon-to-expire resource so that we minimize the number of cache misses when serving live traffic. Note that callback may be NULL, and all subclasses must handle this.
Reimplemented in net_instaweb::CacheableResourceBase.
bool net_instaweb::Resource::is_authorized_domain | ( | ) | [inline] |
Whether the domain on which the resource is present is explicitly authorized or not. Unauthorized resources can be created for the purpose of inlining content into the HTML.
bool net_instaweb::Resource::IsSafeToRewrite | ( | bool | rewrite_uncacheable | ) | const |
Answers question: Are we allowed to rewrite the contents now? Checks if valid and cacheable and if it has a no-transform header. rewrite_uncacheable is used to answer question whether the resource can be optimizaed even if it is not cacheable.
virtual bool net_instaweb::Resource::IsValidAndCacheable | ( | ) | const [virtual] |
Checks if the contents are loaded and valid and also if the resource is up-to-date and cacheable by a proxy like us.
Reimplemented in net_instaweb::DataUrlInputResource, net_instaweb::CacheableResourceBase, and net_instaweb::FileInputResource.
bool net_instaweb::Resource::Link | ( | HTTPValue * | source, |
MessageHandler * | handler | ||
) |
Links in the HTTP contents and header from a fetched value. The contents are linked by sharing. The HTTPValue also contains a serialization of the headers, and this routine parses them into response_headers_ and return whether that was successful.
virtual void net_instaweb::Resource::LoadAndCallback | ( | NotCacheablePolicy | not_cacheable_policy, |
const RequestContextPtr & | request_context, | ||
AsyncCallback * | callback | ||
) | [protected, pure virtual] |
Load the resource asynchronously, storing ResponseHeaders and contents in object. Calls 'callback' when finished. The ResourcePtr used to construct 'callback' must be the same as the resource used to invoke this method.
Setting not_cacheable_policy to kLoadEvenIfNotCacheable will permit it to consider loading to be successful on Cache-Control:private and Cache-Control:no-cache resources. It should not affect /whether/ the callback gets involved, only whether it gets true or false.
Implemented in net_instaweb::DataUrlInputResource, net_instaweb::FileInputResource, net_instaweb::OutputResource, and net_instaweb::CacheableResourceBase.
void net_instaweb::Resource::LoadAsync | ( | NotCacheablePolicy | not_cacheable_policy, |
const RequestContextPtr & | request_context, | ||
AsyncCallback * | callback | ||
) |
Loads contents of resource asynchronously, calling callback when done. If the resource contents are already loaded into the object, the callback will be called directly, rather than asynchronously. The resource will be passed to the callback, with its contents and headers filled in.
This is implemented in terms of LoadAndCallback, taking care of the case where the resource is already loaded.
bool net_instaweb::Resource::loaded | ( | ) | const [inline] |
virtual void net_instaweb::Resource::RefreshIfImminentlyExpiring | ( | ) | [virtual] |
If the resource is about to expire from the cache, re-fetches the resource in background to try to prevent it from expiring.
Base implementation does nothing, since most subclasses of this do not use caching.
Reimplemented in net_instaweb::CacheableResourceBase.
virtual bool net_instaweb::Resource::UseHttpCache | ( | ) | const [pure virtual] |
Returns whether this type of resource should use the HTTP Cache. This method is based on properties of the class, not the resource itself, and helps short-circuit pointless cache lookups for file-based and data URLs.
Implemented in net_instaweb::OutputResource, net_instaweb::DataUrlInputResource, net_instaweb::FileInputResource, and net_instaweb::CacheableResourceBase.
HTTPValue net_instaweb::Resource::fallback_value_ [protected] |
A stale value that can be used in case we aren't able to fetch a fresh version of the resource. Note that this should only be used if it is not empty.