Page Speed Optimization Libraries
1.7.30.1
|
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, MessageHandler* handler, 00055 Callback* callback); 00056 00058 virtual void Delete(const GoogleString& key); 00059 00061 virtual void set_force_caching(bool force); 00062 00064 virtual void set_hasher(Hasher* hasher) { 00065 cache1_->set_hasher(hasher); 00066 cache2_->set_hasher(hasher); 00067 } 00068 00070 virtual void set_disable_html_caching_on_https(bool x); 00071 00073 virtual void set_remember_not_cacheable_ttl_seconds(int64 value); 00074 00076 virtual void set_remember_fetch_failed_ttl_seconds(int64 value); 00077 00079 virtual void set_remember_fetch_dropped_ttl_seconds(int64 value); 00080 00082 virtual void set_max_cacheable_response_content_length(int64 value); 00083 00085 virtual void RememberNotCacheable(const GoogleString& key, 00086 bool is_200_status_code, 00087 MessageHandler * handler); 00088 00090 virtual void RememberFetchFailed(const GoogleString& key, 00091 MessageHandler * handler); 00092 00094 virtual void RememberFetchDropped(const GoogleString& key, 00095 MessageHandler * handler); 00096 00101 void set_cache1_limit(size_t limit) { cache1_size_limit_ = limit; } 00102 size_t cache1_limit() const { return cache1_size_limit_; } 00103 00104 virtual GoogleString Name() const { 00105 return FormatName(cache1_->Name(), cache2_->Name()); 00106 } 00107 static GoogleString FormatName(StringPiece l1, StringPiece l2); 00108 00109 protected: 00111 virtual void PutInternal(const GoogleString& key, int64 start_us, 00112 HTTPValue* value); 00113 00114 private: 00115 void PutInCache1(const GoogleString& key, HTTPValue* value); 00116 00117 scoped_ptr<HTTPCache> cache1_; 00118 scoped_ptr<HTTPCache> cache2_; 00119 size_t cache1_size_limit_; 00120 GoogleString name_; 00121 00122 DISALLOW_COPY_AND_ASSIGN(WriteThroughHTTPCache); 00123 }; 00124 00125 } 00126 00127 #endif ///< NET_INSTAWEB_HTTP_PUBLIC_WRITE_THROUGH_HTTP_CACHE_H_