Page Speed Optimization Libraries
1.6.29.3
|
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 "pagespeed/kernel/base/string.h" 00028 #include "pagespeed/kernel/base/string_util.h" 00029 00030 namespace net_instaweb { 00031 00032 class AbstractMutex; 00033 class SharedString; 00034 class Statistics; 00035 class Variable; 00036 00050 class CacheBatcher : public CacheInterface { 00051 public: 00063 static const int kDefaultMaxParallelLookups = 1; 00064 00069 static const size_t kDefaultMaxQueueSize = 1000; 00070 00072 CacheBatcher(CacheInterface* cache, AbstractMutex* mutex, 00073 Statistics* statistics); 00074 virtual ~CacheBatcher(); 00075 00079 static void InitStats(Statistics* statistics); 00080 00081 virtual void Get(const GoogleString& key, Callback* callback); 00082 virtual void Put(const GoogleString& key, SharedString* value); 00083 virtual void Delete(const GoogleString& key); 00084 virtual GoogleString Name() const; 00085 static GoogleString FormatName(StringPiece cache, int parallelism, int max); 00086 00089 virtual bool IsBlocking() const { return cache_->IsBlocking(); } 00090 00091 int last_batch_size() const { return last_batch_size_; } 00092 void set_max_queue_size(size_t n) { max_queue_size_ = n; } 00093 void set_max_parallel_lookups(size_t n) { max_parallel_lookups_ = n; } 00094 00095 int Pending(); 00096 00097 virtual bool IsHealthy() const { return cache_->IsHealthy(); } 00098 virtual void ShutDown(); 00099 00100 private: 00101 class Group; 00102 class BatcherCallback; 00103 00104 void GroupComplete(); 00105 bool CanIssueGet() const; 00106 00107 CacheInterface* cache_; 00108 scoped_ptr<AbstractMutex> mutex_; 00109 MultiGetRequest queue_; 00110 int last_batch_size_; 00111 int pending_; 00112 int max_parallel_lookups_; 00113 size_t max_queue_size_; 00114 Variable* dropped_gets_; 00115 00116 DISALLOW_COPY_AND_ASSIGN(CacheBatcher); 00117 }; 00118 00119 } 00120 00121 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_CACHE_BATCHER_H_