Page Speed Optimization Libraries  1.6.29.3
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 #include "pagespeed/kernel/base/string_util.h"
00028 
00029 namespace net_instaweb {
00030 
00031 class MessageHandler;
00032 class SharedString;
00033 
00039 class FallbackCache : public CacheInterface {
00040  public:
00044   FallbackCache(CacheInterface* small_object_cache,
00045                 CacheInterface* large_object_cache,
00046                 int threshold_bytes,
00047                 MessageHandler* handler);
00048   virtual ~FallbackCache();
00049 
00050   virtual void Get(const GoogleString& key, Callback* callback);
00051   virtual void Put(const GoogleString& key, SharedString* value);
00052   virtual void Delete(const GoogleString& key);
00053   virtual void MultiGet(MultiGetRequest* request);
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   virtual GoogleString Name() const {
00071     return FormatName(small_object_cache_->Name(), large_object_cache_->Name());
00072   }
00073   static GoogleString FormatName(StringPiece small, StringPiece large);
00074 
00075  private:
00076   void DecodeValueMatchingKeyAndCallCallback(
00077       const GoogleString& key, const char* data, size_t data_len,
00078       Callback* callback);
00079 
00080   CacheInterface* small_object_cache_;
00081   CacheInterface* large_object_cache_;
00082   int threshold_bytes_;
00083   MessageHandler* message_handler_;
00084 
00085   DISALLOW_COPY_AND_ASSIGN(FallbackCache);
00086 };
00087 
00088 }  
00089 
00090 #endif  ///< NET_INSTAWEB_UTIL_PUBLIC_FALLBACK_CACHE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines