Page Speed Optimization Libraries
1.8.31.2
|
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_WRITE_THROUGH_HTTP_CACHE_H_ 00020 #define NET_INSTAWEB_HTTP_PUBLIC_WRITE_THROUGH_HTTP_CACHE_H_ 00021 00022 #include <cstddef> 00023 00024 #include "net/instaweb/http/public/http_cache.h" 00025 #include "net/instaweb/util/public/basictypes.h" 00026 #include "net/instaweb/util/public/scoped_ptr.h" 00027 #include "net/instaweb/util/public/string.h" 00028 #include "pagespeed/kernel/base/string_util.h" 00029 00030 namespace net_instaweb { 00031 00032 class CacheInterface; 00033 class Hasher; 00034 class HTTPValue; 00035 class MessageHandler; 00036 class Statistics; 00037 class Timer; 00038 00040 class WriteThroughHTTPCache : public HTTPCache { 00041 public: 00042 static const size_t kUnlimited; 00043 00045 WriteThroughHTTPCache(CacheInterface* cache1, CacheInterface* cache2, 00046 Timer* timer, Hasher* hasher, Statistics* statistics); 00047 00048 virtual ~WriteThroughHTTPCache(); 00049 00051 virtual void SetIgnoreFailurePuts(); 00052 00054 virtual void Find(const GoogleString& key, 00055 const GoogleString& fragment, 00056 MessageHandler* handler, 00057 Callback* callback); 00058 00060 virtual void Delete(const GoogleString& key, const GoogleString& fragment); 00061 00063 virtual void set_force_caching(bool force); 00064 00066 virtual void set_hasher(Hasher* hasher) { 00067 cache1_->set_hasher(hasher); 00068 cache2_->set_hasher(hasher); 00069 } 00070 00072 virtual void set_disable_html_caching_on_https(bool x); 00073 00075 virtual void set_remember_not_cacheable_ttl_seconds(int64 value); 00076 00078 virtual void set_remember_fetch_failed_ttl_seconds(int64 value); 00079 00081 virtual void set_remember_fetch_dropped_ttl_seconds(int64 value); 00082 00084 virtual void set_max_cacheable_response_content_length(int64 value); 00085 00087 virtual void RememberNotCacheable(const GoogleString& key, 00088 const GoogleString& fragment, 00089 bool is_200_status_code, 00090 MessageHandler * handler); 00091 00093 virtual void RememberFetchFailed(const GoogleString& key, 00094 const GoogleString& fragment, 00095 MessageHandler * handler); 00096 00098 virtual void RememberFetchDropped(const GoogleString& key, 00099 const GoogleString& fragment, 00100 MessageHandler * handler); 00101 00106 void set_cache1_limit(size_t limit) { cache1_size_limit_ = limit; } 00107 size_t cache1_limit() const { return cache1_size_limit_; } 00108 00109 virtual GoogleString Name() const { 00110 return FormatName(cache1_->Name(), cache2_->Name()); 00111 } 00112 static GoogleString FormatName(StringPiece l1, StringPiece l2); 00113 00114 protected: 00116 virtual void PutInternal(const GoogleString& key, 00117 const GoogleString& fragment, 00118 int64 start_us, 00119 HTTPValue* value); 00120 00121 private: 00122 void PutInCache1( 00123 const GoogleString& key, const GoogleString& fragment, HTTPValue* value); 00124 00125 scoped_ptr<HTTPCache> cache1_; 00126 scoped_ptr<HTTPCache> cache2_; 00127 size_t cache1_size_limit_; 00128 GoogleString name_; 00129 00130 DISALLOW_COPY_AND_ASSIGN(WriteThroughHTTPCache); 00131 }; 00132 00133 } 00134 00135 #endif ///< NET_INSTAWEB_HTTP_PUBLIC_WRITE_THROUGH_HTTP_CACHE_H_