Page Speed Optimization Libraries
1.3.25.1
|
Classes | |
class | AsyncCallback |
class | FreshenCallback |
Public Types | |
enum | HashHint { kOmitInputHash, kIncludeInputHash } |
enum | NotCacheablePolicy { kLoadEvenIfNotCacheable, kReportFailureIfNotCacheable } |
enum | FetchResponseStatus { kFetchStatusNotSet, kFetchStatusOK, kFetchStatusUncacheable, kFetchStatus4xxError, 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 | IsSafeToRewrite () const |
bool | loaded () const |
bool | HttpStatusOk () const |
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. | |
void | DetermineContentType () |
virtual const RewriteOptions * | rewrite_options () const =0 |
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, AsyncCallback *callback, MessageHandler *message_handler)=0 |
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 | RewriteDriver |
for ReadIfCachedWithStatus | |
class | UrlReadAsyncFetchCallback |
class | ResourceManagerHttpCallback |
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.
int64 net_instaweb::Resource::CacheExpirationTimeMs | ( | ) | const |
Returns 0 if resource is not cacheable.
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::UrlInputResource.
bool net_instaweb::Resource::IsSafeToRewrite | ( | ) | const |
Answers question: Are we allowed to rewrite the contents now? Checks if valid and cacheable and if it has a no-transform header.
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::FileInputResource, and net_instaweb::UrlInputResource.
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, |
AsyncCallback * | callback, | ||
MessageHandler * | message_handler | ||
) | [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::UrlInputResource.
bool net_instaweb::Resource::loaded | ( | ) | const [inline] |
virtual const RewriteOptions* net_instaweb::Resource::rewrite_options | ( | ) | const [pure virtual] |
Obtain rewrite options for this. Any resources which return true for UseHttpCache() but don't unconditionally return true for loaded() must override this in a useful way. Used in cache invalidation.
Implemented in net_instaweb::OutputResource, net_instaweb::DataUrlInputResource, net_instaweb::FileInputResource, and net_instaweb::UrlInputResource.
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::UrlInputResource.
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.