Page Speed Optimization Libraries
1.4.26.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_ASYNC_CACHE_H_ 00020 #define NET_INSTAWEB_UTIL_PUBLIC_ASYNC_CACHE_H_ 00021 00022 #include "net/instaweb/util/public/atomic_bool.h" 00023 #include "net/instaweb/util/public/atomic_int32.h" 00024 #include "net/instaweb/util/public/basictypes.h" 00025 #include "net/instaweb/util/public/cache_interface.h" 00026 #include "net/instaweb/util/public/queued_worker_pool.h" 00027 #include "net/instaweb/util/public/scoped_ptr.h" 00028 #include "net/instaweb/util/public/string.h" 00029 00030 namespace net_instaweb { 00031 00032 class SharedString; 00033 00040 class AsyncCache : public CacheInterface { 00041 public: 00054 static const int64 kMaxQueueSize = 2000; 00055 00063 AsyncCache(CacheInterface* cache, QueuedWorkerPool* pool); 00064 virtual ~AsyncCache(); 00065 00066 virtual void Get(const GoogleString& key, Callback* callback); 00067 virtual void Put(const GoogleString& key, SharedString* value); 00068 virtual void Delete(const GoogleString& key); 00069 virtual void MultiGet(MultiGetRequest* request); 00070 virtual const char* Name() const { return name_.c_str(); } 00071 virtual bool IsBlocking() const { return false; } 00072 00080 virtual void ShutDown(); 00081 00085 void CancelPendingOperations() { sequence_->CancelPendingFunctions(); } 00086 00087 virtual bool IsHealthy() const { 00088 return !stopped_.value() && cache_->IsHealthy(); 00089 } 00090 00091 int32 outstanding_operations() { return outstanding_operations_.value(); } 00092 00093 private: 00096 void DoGet(GoogleString* key, Callback* callback); 00097 void CancelGet(GoogleString* key, Callback* callback); 00098 00101 void DoMultiGet(MultiGetRequest* request); 00102 void CancelMultiGet(MultiGetRequest* request); 00103 00106 void DoPut(GoogleString* key, SharedString* value); 00107 void CancelPut(GoogleString* key, SharedString* value); 00108 void DoDelete(GoogleString* key); 00109 void CancelDelete(GoogleString* key); 00110 00111 void MultiGetReportNotFound(MultiGetRequest* request); 00112 00113 scoped_ptr<CacheInterface> cache_; 00114 GoogleString name_; 00115 QueuedWorkerPool::Sequence* sequence_; 00116 AtomicBool stopped_; 00117 AtomicInt32 outstanding_operations_; 00118 00119 DISALLOW_COPY_AND_ASSIGN(AsyncCache); 00120 }; 00121 00122 } 00123 00124 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_ASYNC_CACHE_H_