Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fallback_cache.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012 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_FALLBACK_CACHE_H_
20 #define PAGESPEED_KERNEL_CACHE_FALLBACK_CACHE_H_
21 
22 #include <cstddef>
23 
28 #include "pagespeed/kernel/cache/cache_interface.h"
29 
30 namespace net_instaweb {
31 
32 class MessageHandler;
33 
39 class FallbackCache : public CacheInterface {
40  public:
46  FallbackCache(CacheInterface* small_object_cache,
47  CacheInterface* large_object_cache,
48  int threshold_bytes,
49  MessageHandler* handler);
50  virtual ~FallbackCache();
51 
52  virtual void Get(const GoogleString& key, Callback* callback);
53  virtual void Put(const GoogleString& key, const SharedString& value);
54  virtual void Delete(const GoogleString& key);
55  virtual void MultiGet(MultiGetRequest* request);
56  virtual bool IsBlocking() const {
58  return (small_object_cache_->IsBlocking() &&
59  large_object_cache_->IsBlocking());
60  }
61 
62  virtual bool IsHealthy() const {
63  return (small_object_cache_->IsHealthy() &&
64  large_object_cache_->IsHealthy());
65  }
66 
67  virtual void ShutDown() {
68  small_object_cache_->ShutDown();
69  large_object_cache_->ShutDown();
70  }
71 
72  virtual GoogleString Name() const {
73  return FormatName(small_object_cache_->Name(), large_object_cache_->Name());
74  }
75  static GoogleString FormatName(StringPiece small, StringPiece large);
76 
79  void set_account_for_key_size(bool x) { account_for_key_size_ = x; }
80 
81  private:
82  void DecodeValueMatchingKeyAndCallCallback(
83  const GoogleString& key, const char* data, size_t data_len,
84  Callback* callback);
85 
86  CacheInterface* small_object_cache_;
87  CacheInterface* large_object_cache_;
88  int threshold_bytes_;
89  bool account_for_key_size_;
90  MessageHandler* message_handler_;
91 
92 
93 };
94 
95 }
96 
97 #endif
Definition: fallback_cache.h:39
Abstract interface for a cache.
Definition: cache_interface.h:32
virtual GoogleString Name() const
Definition: fallback_cache.h:72
void set_account_for_key_size(bool x)
Definition: fallback_cache.h:79
virtual bool IsHealthy() const
Definition: fallback_cache.h:62
virtual void Get(const GoogleString &key, Callback *callback)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual void Put(const GoogleString &key, const SharedString &value)
virtual void MultiGet(MultiGetRequest *request)
virtual bool IsHealthy() const =0
virtual bool IsBlocking() const =0
Definition: shared_string.h:40
Definition: cache_interface.h:42
virtual bool IsBlocking() const
Definition: fallback_cache.h:56
FallbackCache(CacheInterface *small_object_cache, CacheInterface *large_object_cache, int threshold_bytes, MessageHandler *handler)
Definition: message_handler.h:39
virtual void ShutDown()
Definition: fallback_cache.h:67
virtual GoogleString Name() const =0