Page Speed Optimization Libraries  1.9.32.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
write_through_http_cache.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_WRITE_THROUGH_HTTP_CACHE_H_
20 #define NET_INSTAWEB_HTTP_PUBLIC_WRITE_THROUGH_HTTP_CACHE_H_
21 
22 #include <cstddef>
23 
28 #include "pagespeed/kernel/base/string_util.h"
29 
30 namespace net_instaweb {
31 
32 class CacheInterface;
33 class Hasher;
34 class HTTPValue;
35 class MessageHandler;
36 class Statistics;
37 class Timer;
38 
41  public:
42  static const size_t kUnlimited;
43 
45  WriteThroughHTTPCache(CacheInterface* cache1, CacheInterface* cache2,
46  Timer* timer, Hasher* hasher, Statistics* statistics);
47 
48  virtual ~WriteThroughHTTPCache();
49 
51  virtual void SetIgnoreFailurePuts();
52 
54  virtual void Find(const GoogleString& key,
55  const GoogleString& fragment,
56  MessageHandler* handler,
57  Callback* callback);
58 
60  virtual void DeleteInternal(const GoogleString& key_fragment);
61 
63  virtual void set_force_caching(bool force);
64 
66  virtual void set_hasher(Hasher* hasher) {
67  cache1_->set_hasher(hasher);
68  cache2_->set_hasher(hasher);
69  }
70 
72  virtual void set_disable_html_caching_on_https(bool x);
73 
75  virtual void set_remember_not_cacheable_ttl_seconds(int64 value);
76 
78  virtual void set_remember_fetch_failed_ttl_seconds(int64 value);
79 
81  virtual void set_remember_fetch_dropped_ttl_seconds(int64 value);
82 
84  virtual void set_max_cacheable_response_content_length(int64 value);
85 
87  virtual void RememberNotCacheable(const GoogleString& key,
88  const GoogleString& fragment,
89  bool is_200_status_code,
90  MessageHandler * handler);
91 
93  virtual void RememberFetchFailed(const GoogleString& key,
94  const GoogleString& fragment,
95  MessageHandler * handler);
96 
98  virtual void RememberFetchDropped(const GoogleString& key,
99  const GoogleString& fragment,
100  MessageHandler * handler);
101 
106  void set_cache1_limit(size_t limit) { cache1_size_limit_ = limit; }
107  size_t cache1_limit() const { return cache1_size_limit_; }
108 
109  virtual GoogleString Name() const {
110  return FormatName(cache1_->Name(), cache2_->Name());
111  }
112  static GoogleString FormatName(StringPiece l1, StringPiece l2);
113 
114  protected:
116  virtual void PutInternal(const GoogleString& key,
117  const GoogleString& fragment,
118  int64 start_us,
119  HTTPValue* value);
120 
121  private:
122  void PutInCache1(
123  const GoogleString& key, const GoogleString& fragment, HTTPValue* value);
124 
125  scoped_ptr<HTTPCache> cache1_;
126  scoped_ptr<HTTPCache> cache2_;
127  size_t cache1_size_limit_;
128  GoogleString name_;
129 
130  DISALLOW_COPY_AND_ASSIGN(WriteThroughHTTPCache);
131 };
132 
133 }
134 
135 #endif
Composes two cache interfaces to form a two level http cache.
Definition: write_through_http_cache.h:40
virtual void RememberNotCacheable(const GoogleString &key, const GoogleString &fragment, bool is_200_status_code, MessageHandler *handler)
Implements HTTPCache::RememberNotCacheable().
virtual void DeleteInternal(const GoogleString &key_fragment)
Implements HTTPCache::DeleteInternal().
virtual void SetIgnoreFailurePuts()
Implements HTTPCache::SetIgnoreFailurePuts().
void set_cache1_limit(size_t limit)
Definition: write_through_http_cache.h:106
virtual void set_hasher(Hasher *hasher)
Implements HttpCache::set_hasher().
Definition: write_through_http_cache.h:66
virtual void set_remember_not_cacheable_ttl_seconds(int64 value)
Implements HTTPCache::set_remember_not_cacheable_ttl_seconds().
virtual void Find(const GoogleString &key, const GoogleString &fragment, MessageHandler *handler, Callback *callback)
Implements HTTPCache::Find().
WriteThroughHTTPCache(CacheInterface *cache1, CacheInterface *cache2, Timer *timer, Hasher *hasher, Statistics *statistics)
Takes ownership of both caches passed in.
virtual void RememberFetchDropped(const GoogleString &key, const GoogleString &fragment, MessageHandler *handler)
Implements HTTPCache::RememberFetchDropped().
virtual void set_max_cacheable_response_content_length(int64 value)
Implements HTTPCache::set_max_cacheable_response_content_length().
virtual void set_remember_fetch_dropped_ttl_seconds(int64 value)
Implements HTTPCache::set_remember_fetch_dropped_ttl_seconds();.
virtual void PutInternal(const GoogleString &key, const GoogleString &fragment, int64 start_us, HTTPValue *value)
Implements HTTPCache::PutInternal().
virtual void set_remember_fetch_failed_ttl_seconds(int64 value)
Implements HTTPCache::set_remember_fetch_failed_ttl_seconds().
virtual void set_disable_html_caching_on_https(bool x)
Implements HTTPCache::set_disable_html_caching_on_https().
Definition: http_cache.h:87
virtual void set_force_caching(bool force)
Implements HTTPCache::set_force_caching().
virtual void RememberFetchFailed(const GoogleString &key, const GoogleString &fragment, MessageHandler *handler)
Implements HTTPCache::RememberFetchFailed().
Definition: http_cache.h:46