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 "base/scoped_ptr.h" 00035 #include "net/instaweb/util/public/basictypes.h" 00036 #include "net/instaweb/util/public/cache_interface.h" 00037 #include "net/instaweb/util/public/queued_worker_pool.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 00062 void DelayKey(const GoogleString& key); 00063 00066 void ReleaseKey(const GoogleString& key) { ReleaseKeyInSequence(key, NULL); } 00067 00071 void ReleaseKeyInSequence(const GoogleString& key, 00072 QueuedWorkerPool::Sequence* sequence); 00073 00074 virtual const char* Name() const { return name_.c_str(); } 00075 00076 private: 00077 class DelayCallback; 00078 friend class DelayCallback; 00079 00080 void LookupComplete(DelayCallback* callback); 00081 00082 typedef std::map<GoogleString, DelayCallback*> DelayMap; 00083 00084 CacheInterface* cache_; 00085 scoped_ptr<AbstractMutex> mutex_; 00086 StringSet delay_requests_; 00087 DelayMap delay_map_; 00088 GoogleString name_; 00089 00090 DISALLOW_COPY_AND_ASSIGN(DelayCache); 00091 }; 00092 00093 } 00094 00095 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_DELAY_CACHE_H_