Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cacheable_resource_base.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
25 
26 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CACHEABLE_RESOURCE_BASE_H_
27 #define NET_INSTAWEB_REWRITER_PUBLIC_CACHEABLE_RESOURCE_BASE_H_
28 
29 #include "net/instaweb/http/public/request_context.h"
35 
36 namespace net_instaweb {
37 
38 struct ContentType;
39 class HTTPCache;
40 class HTTPValue;
41 class MessageHandler;
42 class RequestHeaders;
43 class ResponseHeaders;
44 class RewriteDriver;
45 class RewriteOptions;
46 class Statistics;
47 class Timer;
48 class Variable;
49 
51  public:
53 
55  virtual bool UseHttpCache() const { return true; }
56 
57  virtual bool IsValidAndCacheable() const;
58 
60  virtual void LoadAndCallback(NotCacheablePolicy not_cacheable_policy,
61  const RequestContextPtr& request_context,
62  AsyncCallback* callback);
63 
64  virtual void Freshen(FreshenCallback* callback, MessageHandler* handler);
65  virtual void RefreshIfImminentlyExpiring();
66  virtual GoogleString url() const { return url_; }
67  virtual GoogleString cache_key() const { return cache_key_; }
68 
69  protected:
71  CacheableResourceBase(StringPiece stat_prefix,
72  StringPiece url,
73  StringPiece cache_key,
74  const ContentType* type,
75  RewriteDriver* rewrite_driver);
76  virtual ~CacheableResourceBase();
77 
78  static void InitStats(StringPiece stat_prefix, Statistics* statistics);
79 
82  virtual void PrepareRequest(const RequestContextPtr& request_context,
83  RequestHeaders* headers);
84 
89  virtual void PrepareResponseHeaders(ResponseHeaders* headers);
90 
91  HTTPCache* http_cache() const { return server_context()->http_cache(); }
92  RewriteDriver* rewrite_driver() const { return rewrite_driver_; }
93  const RewriteOptions* rewrite_options() const;
94 
97  bool ShouldSkipBackgroundFetch() const;
98 
99  private:
100  class FreshenHttpCacheCallback;
101  class LoadHttpCacheCallback;
102  class FetchCallbackBase;
103  class FreshenFetchCallback;
104  class LoadFetchCallback;
105  friend class CacheableResourceBaseTest;
106 
110  bool UpdateInputInfoForFreshen(const ResponseHeaders& headers,
111  const HTTPValue& value,
112  Resource::FreshenCallback* callback);
113 
116  bool IsValidAndCacheableImpl(const ResponseHeaders& headers) const;
117 
118  Timer* timer() const { return server_context()->timer(); }
119  MessageHandler* message_handler() const {
120  return server_context()->message_handler();
121  }
122 
123  GoogleString url_;
124  GoogleString cache_key_;
125 
126  RewriteDriver* rewrite_driver_;
127  Variable* hits_;
128  Variable* recent_fetch_failures_;
129  Variable* recent_uncacheables_miss_;
130  Variable* recent_uncacheables_failure_;
131  Variable* misses_;
132 
133 
134 };
135 
136 }
137 
138 #endif
virtual void LoadAndCallback(NotCacheablePolicy not_cacheable_policy, const RequestContextPtr &request_context, AsyncCallback *callback)
This checks the cache, and fetches the resource if appropriate.
Read/write API for HTTP request (RequestHeaders is a misnomer).
Definition: request_headers.h:32
ServerContext * server_context() const
Common methods across all deriviations.
Definition: resource.h:77
virtual void PrepareRequest(const RequestContextPtr &request_context, RequestHeaders *headers)
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
virtual void PrepareResponseHeaders(ResponseHeaders *headers)
Read/write API for HTTP response headers.
Definition: response_headers.h:37
Definition: resource.h:57
NotCacheablePolicy
Definition: resource.h:68
virtual void Freshen(FreshenCallback *callback, MessageHandler *handler)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: rewrite_driver.h:100
CacheableResourceBase(StringPiece stat_prefix, StringPiece url, StringPiece cache_key, const ContentType *type, RewriteDriver *rewrite_driver)
Note: InitStats(stat_prefix) must have been called before.
friend class RewriteDriver
for ReadIfCachedWithStatus
Definition: resource.h:289
Definition: content_type.h:31
virtual bool IsValidAndCacheable() const
Definition: message_handler.h:39
virtual bool UseHttpCache() const
All the public methods here implement the Resource API.
Definition: cacheable_resource_base.h:55
Definition: cacheable_resource_base.h:50
virtual GoogleString cache_key() const
Definition: cacheable_resource_base.h:67
virtual GoogleString url() const
Gets the absolute URL of the resource.
Definition: cacheable_resource_base.h:66
Definition: http_cache.h:67