Page Speed Optimization Libraries  1.2.24.1
net/instaweb/util/public/fallback_cache.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012 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_UTIL_PUBLIC_FALLBACK_CACHE_H_
00020 #define NET_INSTAWEB_UTIL_PUBLIC_FALLBACK_CACHE_H_
00021 
00022 #include <cstddef>
00023 
00024 #include "net/instaweb/util/public/basictypes.h"
00025 #include "net/instaweb/util/public/cache_interface.h"
00026 #include "net/instaweb/util/public/string.h"
00027 
00028 namespace net_instaweb {
00029 
00030 class MessageHandler;
00031 class SharedString;
00032 
00038 class FallbackCache : public CacheInterface {
00039  public:
00043   FallbackCache(CacheInterface* small_object_cache,
00044                 CacheInterface* large_object_cache,
00045                 int threshold_bytes,
00046                 MessageHandler* handler);
00047   virtual ~FallbackCache();
00048 
00049   virtual void Get(const GoogleString& key, Callback* callback);
00050   virtual void Put(const GoogleString& key, SharedString* value);
00051   virtual void Delete(const GoogleString& key);
00052   virtual void MultiGet(MultiGetRequest* request);
00053   virtual const char* Name() const { return name_.c_str(); }
00054   virtual bool IsBlocking() const {
00056     return (small_object_cache_->IsBlocking() &&
00057             large_object_cache_->IsBlocking());
00058   }
00059 
00060   virtual bool IsHealthy() const {
00061     return (small_object_cache_->IsHealthy() &&
00062             large_object_cache_->IsHealthy());
00063   }
00064 
00065   virtual void ShutDown() {
00066     small_object_cache_->ShutDown();
00067     large_object_cache_->ShutDown();
00068   }
00069 
00070  private:
00071   void DecodeValueMatchingKeyAndCallCallback(
00072       const GoogleString& key, const char* data, size_t data_len,
00073       Callback* callback);
00074 
00075   CacheInterface* small_object_cache_;
00076   CacheInterface* large_object_cache_;
00077   int threshold_bytes_;
00078   MessageHandler* message_handler_;
00079   GoogleString name_;
00080 
00081   DISALLOW_COPY_AND_ASSIGN(FallbackCache);
00082 };
00083 
00084 }  
00085 
00086 #endif  ///< NET_INSTAWEB_UTIL_PUBLIC_FALLBACK_CACHE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines