Page Speed Optimization Libraries  1.5.27.2
net/instaweb/util/public/async_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 
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 "pagespeed/kernel/base/string.h"
00028 #include "pagespeed/kernel/base/string_util.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   static GoogleString FormatName(StringPiece cache);
00071   virtual GoogleString Name() const { return FormatName(cache_->Name()); }
00072   virtual bool IsBlocking() const { return false; }
00073 
00081   virtual void ShutDown();
00082 
00086   void CancelPendingOperations() { sequence_->CancelPendingFunctions(); }
00087 
00088   virtual bool IsHealthy() const {
00089     return !stopped_.value() && cache_->IsHealthy();
00090   }
00091 
00092   int32 outstanding_operations() { return outstanding_operations_.value(); }
00093 
00094  private:
00097   void DoGet(GoogleString* key, Callback* callback);
00098   void CancelGet(GoogleString* key, Callback* callback);
00099 
00102   void DoMultiGet(MultiGetRequest* request);
00103   void CancelMultiGet(MultiGetRequest* request);
00104 
00107   void DoPut(GoogleString* key, SharedString* value);
00108   void CancelPut(GoogleString* key, SharedString* value);
00109   void DoDelete(GoogleString* key);
00110   void CancelDelete(GoogleString* key);
00111 
00112   void MultiGetReportNotFound(MultiGetRequest* request);
00113 
00114   CacheInterface* cache_;
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_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines