Page Speed Optimization Libraries
1.2.24.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 00028 00029 #ifndef NET_INSTAWEB_UTIL_PUBLIC_DELAY_CACHE_H_ 00030 #define NET_INSTAWEB_UTIL_PUBLIC_DELAY_CACHE_H_ 00031 00032 #include <map> 00033 00034 #include "net/instaweb/util/public/basictypes.h" 00035 #include "net/instaweb/util/public/cache_interface.h" 00036 #include "net/instaweb/util/public/queued_worker_pool.h" 00037 #include "net/instaweb/util/public/scoped_ptr.h" 00038 #include "net/instaweb/util/public/string.h" 00039 #include "net/instaweb/util/public/string_util.h" 00040 00041 namespace net_instaweb { 00042 00043 class AbstractMutex; 00044 class SharedString; 00045 class ThreadSystem; 00046 00048 class DelayCache : public CacheInterface { 00049 public: 00051 DelayCache(CacheInterface* cache, ThreadSystem* thread_system); 00052 virtual ~DelayCache(); 00053 00055 virtual void Get(const GoogleString& key, Callback* callback); 00056 virtual void Put(const GoogleString& key, SharedString* value); 00057 virtual void Delete(const GoogleString& key); 00058 virtual void MultiGet(MultiGetRequest* request); 00059 00063 void DelayKey(const GoogleString& key); 00064 00067 void ReleaseKey(const GoogleString& key) { ReleaseKeyInSequence(key, NULL); } 00068 00072 void ReleaseKeyInSequence(const GoogleString& key, 00073 QueuedWorkerPool::Sequence* sequence); 00074 00075 virtual const char* Name() const { return name_.c_str(); } 00076 virtual bool IsBlocking() const { return false; } 00077 virtual bool IsHealthy() const { return cache_->IsHealthy(); } 00078 virtual void ShutDown() { cache_->ShutDown(); } 00079 00080 private: 00081 class DelayCallback; 00082 friend class DelayCallback; 00083 00084 void LookupComplete(DelayCallback* callback); 00085 00086 typedef std::map<GoogleString, DelayCallback*> DelayMap; 00087 00088 CacheInterface* cache_; 00089 scoped_ptr<AbstractMutex> mutex_; 00090 StringSet delay_requests_; 00091 DelayMap delay_map_; 00092 GoogleString name_; 00093 00094 DISALLOW_COPY_AND_ASSIGN(DelayCache); 00095 }; 00096 00097 } 00098 00099 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_DELAY_CACHE_H_