Page Speed Optimization Libraries  1.7.30.2
net/instaweb/http/public/cache_url_async_fetcher.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2011 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00018 
00019 #ifndef NET_INSTAWEB_HTTP_PUBLIC_CACHE_URL_ASYNC_FETCHER_H_
00020 #define NET_INSTAWEB_HTTP_PUBLIC_CACHE_URL_ASYNC_FETCHER_H_
00021 
00022 #include "net/instaweb/http/public/url_async_fetcher.h"
00023 #include "net/instaweb/util/public/basictypes.h"
00024 #include "net/instaweb/util/public/string.h"
00025 
00026 namespace net_instaweb {
00027 
00028 class AsyncFetch;
00029 class Hasher;
00030 class Histogram;
00031 class HTTPCache;
00032 class MessageHandler;
00033 class NamedLockManager;
00034 class Variable;
00035 
00057 class CacheUrlAsyncFetcher : public UrlAsyncFetcher {
00058  public:
00061   class AsyncOpHooks {
00062    public:
00063     AsyncOpHooks() {}
00064     virtual ~AsyncOpHooks();
00065 
00067     virtual void StartAsyncOp() = 0;
00069     virtual void FinishAsyncOp() = 0;
00070   };
00071 
00073   CacheUrlAsyncFetcher(const Hasher* lock_hasher,
00074                        NamedLockManager* lock_manager,
00075                        HTTPCache* cache,
00076                        AsyncOpHooks* async_op_hooks,
00077                        UrlAsyncFetcher* fetcher)
00078       : lock_hasher_(lock_hasher),
00079         lock_manager_(lock_manager),
00080         http_cache_(cache),
00081         fetcher_(fetcher),
00082         async_op_hooks_(async_op_hooks),
00083         backend_first_byte_latency_(NULL),
00084         fallback_responses_served_(NULL),
00085         fallback_responses_served_while_revalidate_(NULL),
00086         num_conditional_refreshes_(NULL),
00087         num_proactively_freshen_user_facing_request_(NULL),
00088         respect_vary_(false),
00089         ignore_recent_fetch_failed_(false),
00090         serve_stale_if_fetch_error_(false),
00091         default_cache_html_(false),
00092         proactively_freshen_user_facing_request_(false),
00093         serve_stale_while_revalidate_threshold_sec_(0) {
00094   }
00095   virtual ~CacheUrlAsyncFetcher();
00096 
00097   virtual bool SupportsHttps() const { return fetcher_->SupportsHttps(); }
00098 
00099   virtual void Fetch(const GoogleString& url,
00100                      MessageHandler* message_handler,
00101                      AsyncFetch* base_fetch);
00102 
00105   static const int kNotInCacheStatus;
00106 
00107   HTTPCache* http_cache() const { return http_cache_; }
00108   UrlAsyncFetcher* fetcher() const { return fetcher_; }
00109 
00110   void set_backend_first_byte_latency_histogram(Histogram* x) {
00111     backend_first_byte_latency_ = x;
00112   }
00113 
00114   Histogram* backend_first_byte_latency_histogram() const {
00115     return backend_first_byte_latency_;
00116   }
00117 
00118   void set_fallback_responses_served(Variable* x) {
00119     fallback_responses_served_ = x;
00120   }
00121 
00122   Variable* fallback_responses_served() const {
00123     return fallback_responses_served_;
00124   }
00125 
00126   void set_fallback_responses_served_while_revalidate(Variable* x) {
00127     fallback_responses_served_while_revalidate_ = x;
00128   }
00129 
00130   Variable* fallback_responses_served_while_revalidate() const {
00131     return fallback_responses_served_while_revalidate_;
00132   }
00133 
00134   void set_num_conditional_refreshes(Variable* x) {
00135     num_conditional_refreshes_ = x;
00136   }
00137 
00138   Variable* num_conditional_refreshes() const {
00139     return num_conditional_refreshes_;
00140   }
00141 
00142   void set_num_proactively_freshen_user_facing_request(Variable* x) {
00143     num_proactively_freshen_user_facing_request_ = x;
00144   }
00145 
00146   Variable* num_proactively_freshen_user_facing_request() const {
00147     return num_proactively_freshen_user_facing_request_;
00148   }
00149 
00150   void set_respect_vary(bool x) { respect_vary_ = x; }
00151   bool respect_vary() const { return respect_vary_; }
00152 
00153   void set_ignore_recent_fetch_failed(bool x) {
00154     ignore_recent_fetch_failed_ = x;
00155   }
00156   bool ignore_recent_fetch_failed() const {
00157     return ignore_recent_fetch_failed_;
00158   }
00159 
00160   void set_serve_stale_if_fetch_error(bool x) {
00161     serve_stale_if_fetch_error_ = x;
00162   }
00163 
00164   bool serve_stale_if_fetch_error() const {
00165     return serve_stale_if_fetch_error_;
00166   }
00167 
00168   void set_serve_stale_while_revalidate_threshold_sec(int64 x) {
00169     serve_stale_while_revalidate_threshold_sec_ = x;
00170   }
00171 
00172   int64 serve_stale_while_revalidate_threshold_sec() const {
00173     return serve_stale_while_revalidate_threshold_sec_;
00174   }
00175 
00176   void set_default_cache_html(bool x) { default_cache_html_ = x; }
00177   bool default_cache_html() const { return default_cache_html_; }
00178 
00179   void set_proactively_freshen_user_facing_request(bool x) {
00180     proactively_freshen_user_facing_request_ = x;
00181   }
00182   bool proactively_freshen_user_facing_request() const {
00183     return proactively_freshen_user_facing_request_;
00184   }
00185 
00186  private:
00188   const Hasher* lock_hasher_;
00189   NamedLockManager* lock_manager_;
00190   HTTPCache* http_cache_;
00191   UrlAsyncFetcher* fetcher_; 
00192   AsyncOpHooks* async_op_hooks_;
00193 
00194   Histogram* backend_first_byte_latency_; 
00195   Variable* fallback_responses_served_; 
00196   Variable* fallback_responses_served_while_revalidate_; 
00197   Variable* num_conditional_refreshes_; 
00198   Variable* num_proactively_freshen_user_facing_request_; 
00199 
00200   bool respect_vary_;
00201   bool ignore_recent_fetch_failed_;
00202   bool serve_stale_if_fetch_error_;
00203   bool default_cache_html_;
00204   bool proactively_freshen_user_facing_request_;
00205   int64 serve_stale_while_revalidate_threshold_sec_;
00206 
00207   DISALLOW_COPY_AND_ASSIGN(CacheUrlAsyncFetcher);
00208 };
00209 
00210 }  
00211 
00212 #endif  ///< NET_INSTAWEB_HTTP_PUBLIC_CACHE_URL_ASYNC_FETCHER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines