Page Speed Optimization Libraries  1.6.29.3
net/instaweb/util/public/delay_cache.h
Go to the documentation of this file.
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   static GoogleString FormatName(StringPiece name);
00076   virtual GoogleString Name() const { return FormatName(cache_->Name()); }
00077 
00078   virtual bool IsBlocking() const { return false; }
00079   virtual bool IsHealthy() const { return cache_->IsHealthy(); }
00080   virtual void ShutDown() { cache_->ShutDown(); }
00081 
00082  private:
00083   class DelayCallback;
00084   friend class DelayCallback;
00085 
00086   void LookupComplete(DelayCallback* callback);
00087 
00088   typedef std::map<GoogleString, DelayCallback*> DelayMap;
00089 
00090   CacheInterface* cache_;
00091   scoped_ptr<AbstractMutex> mutex_;
00092   StringSet delay_requests_;
00093   DelayMap delay_map_;
00094 
00095   DISALLOW_COPY_AND_ASSIGN(DelayCache);
00096 };
00097 
00098 }  
00099 
00100 #endif  ///< NET_INSTAWEB_UTIL_PUBLIC_DELAY_CACHE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines