Page Speed Optimization Libraries
1.3.25.1
|
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_CACHE_BATCHER_H_ 00020 #define NET_INSTAWEB_UTIL_PUBLIC_CACHE_BATCHER_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/scoped_ptr.h" 00027 #include "net/instaweb/util/public/string.h" 00028 00029 namespace net_instaweb { 00030 00031 class AbstractMutex; 00032 class SharedString; 00033 class Statistics; 00034 class Variable; 00035 00049 class CacheBatcher : public CacheInterface { 00050 public: 00062 static const int kDefaultMaxParallelLookups = 1; 00063 00068 static const size_t kDefaultMaxQueueSize = 1000; 00069 00071 CacheBatcher(CacheInterface* cache, AbstractMutex* mutex, 00072 Statistics* statistics); 00073 virtual ~CacheBatcher(); 00074 00078 static void InitStats(Statistics* statistics); 00079 00080 virtual void Get(const GoogleString& key, Callback* callback); 00081 virtual void Put(const GoogleString& key, SharedString* value); 00082 virtual void Delete(const GoogleString& key); 00083 virtual const char* Name() const { return name_.c_str(); } 00084 00087 virtual bool IsBlocking() const { return cache_->IsBlocking(); } 00088 00089 int last_batch_size() const { return last_batch_size_; } 00090 void set_max_queue_size(size_t n) { max_queue_size_ = n; } 00091 void set_max_parallel_lookups(size_t n) { max_parallel_lookups_ = n; } 00092 00093 int Pending(); 00094 00095 virtual bool IsHealthy() const { return cache_->IsHealthy(); } 00096 virtual void ShutDown(); 00097 00098 private: 00099 class Group; 00100 class BatcherCallback; 00101 00102 void GroupComplete(); 00103 bool CanIssueGet() const; 00104 00105 scoped_ptr<CacheInterface> cache_; 00106 scoped_ptr<AbstractMutex> mutex_; 00107 GoogleString name_; 00108 MultiGetRequest queue_; 00109 int last_batch_size_; 00110 int pending_; 00111 int max_parallel_lookups_; 00112 size_t max_queue_size_; 00113 Variable* dropped_gets_; 00114 00115 DISALLOW_COPY_AND_ASSIGN(CacheBatcher); 00116 }; 00117 00118 } 00119 00120 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_CACHE_BATCHER_H_