Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
write_through_cache.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 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 PAGESPEED_KERNEL_CACHE_WRITE_THROUGH_CACHE_H_
20 #define PAGESPEED_KERNEL_CACHE_WRITE_THROUGH_CACHE_H_
21 
22 #include <cstddef>
23 
28 #include "pagespeed/kernel/cache/cache_interface.h"
29 
30 namespace net_instaweb {
31 
34  public:
35  static const size_t kUnlimited;
36 
39  : cache1_(cache1),
40  cache2_(cache2),
41  cache1_size_limit_(kUnlimited) {
42  }
43 
44  virtual ~WriteThroughCache();
45 
46  virtual void Get(const GoogleString& key, Callback* callback);
47  virtual void Put(const GoogleString& key, const SharedString& value);
48  virtual void Delete(const GoogleString& key);
49 
54  void set_cache1_limit(size_t limit) { cache1_size_limit_ = limit; }
55  size_t cache1_limit() const { return cache1_size_limit_; }
56 
57  CacheInterface* cache1() { return cache1_; }
58  CacheInterface* cache2() { return cache2_; }
59  virtual bool IsBlocking() const {
61  return cache1_->IsBlocking() && cache2_->IsBlocking();
62  }
63 
64  virtual bool IsHealthy() const {
65  return cache1_->IsHealthy() && cache2_->IsHealthy();
66  }
67 
68  virtual void ShutDown() {
69  cache1_->ShutDown();
70  cache2_->ShutDown();
71  }
72 
73  virtual GoogleString Name() const {
74  return FormatName(cache1_->Name(), cache2_->Name());
75  }
76  static GoogleString FormatName(StringPiece l1, StringPiece l2);
77 
78  private:
79  void PutInCache1(const GoogleString& key, const SharedString& value);
80  friend class WriteThroughCallback;
81 
82  CacheInterface* cache1_;
83  CacheInterface* cache2_;
84  size_t cache1_size_limit_;
85 
86 
87 };
88 
89 }
90 
91 #endif
WriteThroughCache(CacheInterface *cache1, CacheInterface *cache2)
Does not take ownership of caches passed in.
Definition: write_through_cache.h:38
Abstract interface for a cache.
Definition: cache_interface.h:32
virtual bool IsHealthy() const
Definition: write_through_cache.h:64
virtual void ShutDown()
Definition: write_through_cache.h:68
void set_cache1_limit(size_t limit)
Definition: write_through_cache.h:54
virtual void Get(const GoogleString &key, Callback *callback)
virtual void Put(const GoogleString &key, const SharedString &value)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual GoogleString Name() const
Definition: write_through_cache.h:73
virtual bool IsHealthy() const =0
virtual bool IsBlocking() const =0
Composes two caches to form a write-through cache.
Definition: write_through_cache.h:33
Definition: shared_string.h:40
virtual GoogleString Name() const =0
virtual bool IsBlocking() const
Definition: write_through_cache.h:59