Page Speed Optimization Libraries  1.9.32.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cache_url_async_fetcher.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 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 
18 
19 #ifndef NET_INSTAWEB_HTTP_PUBLIC_CACHE_URL_ASYNC_FETCHER_H_
20 #define NET_INSTAWEB_HTTP_PUBLIC_CACHE_URL_ASYNC_FETCHER_H_
21 
25 
26 namespace net_instaweb {
27 
28 class AsyncFetch;
29 class Hasher;
30 class Histogram;
31 class HTTPCache;
32 class MessageHandler;
33 class NamedLockManager;
34 class Variable;
35 
58  public:
61  class AsyncOpHooks {
62  public:
63  AsyncOpHooks() {}
64  virtual ~AsyncOpHooks();
65 
67  virtual void StartAsyncOp() = 0;
69  virtual void FinishAsyncOp() = 0;
70  };
71 
73  CacheUrlAsyncFetcher(const Hasher* lock_hasher,
74  NamedLockManager* lock_manager,
75  HTTPCache* cache,
76  const GoogleString& fragment,
77  AsyncOpHooks* async_op_hooks,
78  UrlAsyncFetcher* fetcher)
79  : lock_hasher_(lock_hasher),
80  lock_manager_(lock_manager),
81  http_cache_(cache),
82  fragment_(fragment),
83  fetcher_(fetcher),
84  async_op_hooks_(async_op_hooks),
85  backend_first_byte_latency_(NULL),
86  fallback_responses_served_(NULL),
87  fallback_responses_served_while_revalidate_(NULL),
88  num_conditional_refreshes_(NULL),
89  num_proactively_freshen_user_facing_request_(NULL),
90  respect_vary_(false),
91  ignore_recent_fetch_failed_(false),
92  serve_stale_if_fetch_error_(false),
93  default_cache_html_(false),
94  proactively_freshen_user_facing_request_(false),
95  serve_stale_while_revalidate_threshold_sec_(0) {
96  }
97  virtual ~CacheUrlAsyncFetcher();
98 
99  virtual bool SupportsHttps() const { return fetcher_->SupportsHttps(); }
100 
101  virtual void Fetch(const GoogleString& url,
102  MessageHandler* message_handler,
103  AsyncFetch* base_fetch);
104 
107  static const int kNotInCacheStatus;
108 
109  HTTPCache* http_cache() const { return http_cache_; }
110  UrlAsyncFetcher* fetcher() const { return fetcher_; }
111 
112  void set_backend_first_byte_latency_histogram(Histogram* x) {
113  backend_first_byte_latency_ = x;
114  }
115 
116  Histogram* backend_first_byte_latency_histogram() const {
117  return backend_first_byte_latency_;
118  }
119 
120  void set_fallback_responses_served(Variable* x) {
121  fallback_responses_served_ = x;
122  }
123 
124  Variable* fallback_responses_served() const {
125  return fallback_responses_served_;
126  }
127 
128  void set_fallback_responses_served_while_revalidate(Variable* x) {
129  fallback_responses_served_while_revalidate_ = x;
130  }
131 
132  Variable* fallback_responses_served_while_revalidate() const {
133  return fallback_responses_served_while_revalidate_;
134  }
135 
136  void set_num_conditional_refreshes(Variable* x) {
137  num_conditional_refreshes_ = x;
138  }
139 
140  Variable* num_conditional_refreshes() const {
141  return num_conditional_refreshes_;
142  }
143 
144  void set_num_proactively_freshen_user_facing_request(Variable* x) {
145  num_proactively_freshen_user_facing_request_ = x;
146  }
147 
148  Variable* num_proactively_freshen_user_facing_request() const {
149  return num_proactively_freshen_user_facing_request_;
150  }
151 
152  void set_respect_vary(bool x) { respect_vary_ = x; }
153  bool respect_vary() const { return respect_vary_; }
154 
155  void set_ignore_recent_fetch_failed(bool x) {
156  ignore_recent_fetch_failed_ = x;
157  }
158  bool ignore_recent_fetch_failed() const {
159  return ignore_recent_fetch_failed_;
160  }
161 
162  void set_serve_stale_if_fetch_error(bool x) {
163  serve_stale_if_fetch_error_ = x;
164  }
165 
166  bool serve_stale_if_fetch_error() const {
167  return serve_stale_if_fetch_error_;
168  }
169 
170  void set_serve_stale_while_revalidate_threshold_sec(int64 x) {
171  serve_stale_while_revalidate_threshold_sec_ = x;
172  }
173 
174  int64 serve_stale_while_revalidate_threshold_sec() const {
175  return serve_stale_while_revalidate_threshold_sec_;
176  }
177 
178  void set_default_cache_html(bool x) { default_cache_html_ = x; }
179  bool default_cache_html() const { return default_cache_html_; }
180 
181  void set_proactively_freshen_user_facing_request(bool x) {
182  proactively_freshen_user_facing_request_ = x;
183  }
184  bool proactively_freshen_user_facing_request() const {
185  return proactively_freshen_user_facing_request_;
186  }
187 
188  private:
190  const Hasher* lock_hasher_;
191  NamedLockManager* lock_manager_;
192  HTTPCache* http_cache_;
193  GoogleString fragment_;
194  UrlAsyncFetcher* fetcher_;
195  AsyncOpHooks* async_op_hooks_;
196 
197  Histogram* backend_first_byte_latency_;
198  Variable* fallback_responses_served_;
199  Variable* fallback_responses_served_while_revalidate_;
200  Variable* num_conditional_refreshes_;
201  Variable* num_proactively_freshen_user_facing_request_;
202 
203  bool respect_vary_;
204  bool ignore_recent_fetch_failed_;
205  bool serve_stale_if_fetch_error_;
206  bool default_cache_html_;
207  bool proactively_freshen_user_facing_request_;
208  int64 serve_stale_while_revalidate_threshold_sec_;
209 
210  DISALLOW_COPY_AND_ASSIGN(CacheUrlAsyncFetcher);
211 };
212 
213 }
214 
215 #endif
virtual void FinishAsyncOp()=0
Called when async operation is ended.
virtual void StartAsyncOp()=0
Called when CacheUrlAsyncFetcher is about to start async operation.
virtual bool SupportsHttps() const
Definition: cache_url_async_fetcher.h:99
CacheUrlAsyncFetcher(const Hasher *lock_hasher, NamedLockManager *lock_manager, HTTPCache *cache, const GoogleString &fragment, AsyncOpHooks *async_op_hooks, UrlAsyncFetcher *fetcher)
None of these are owned by CacheUrlAsyncFetcher.
Definition: cache_url_async_fetcher.h:73
Definition: async_fetch.h:53
Definition: cache_url_async_fetcher.h:57
Definition: cache_url_async_fetcher.h:61
virtual void Fetch(const GoogleString &url, MessageHandler *message_handler, AsyncFetch *base_fetch)
UrlAsyncFetcher()
Definition: url_async_fetcher.h:81
virtual bool SupportsHttps() const
Definition: url_async_fetcher.h:57
Definition: url_async_fetcher.h:33
static const int kNotInCacheStatus
Definition: cache_url_async_fetcher.h:107
Definition: http_cache.h:46