Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
async_cache.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef PAGESPEED_KERNEL_CACHE_ASYNC_CACHE_H_
20 #define PAGESPEED_KERNEL_CACHE_ASYNC_CACHE_H_
21 
28 #include "pagespeed/kernel/cache/cache_interface.h"
30 
31 namespace net_instaweb {
32 
39 class AsyncCache : public CacheInterface {
40  public:
53  static const int64 kMaxQueueSize = 2000;
54 
63  virtual ~AsyncCache();
64 
65  virtual void Get(const GoogleString& key, Callback* callback);
66  virtual void Put(const GoogleString& key, const SharedString& value);
67  virtual void Delete(const GoogleString& key);
68  virtual void MultiGet(MultiGetRequest* request);
69  static GoogleString FormatName(StringPiece cache);
70  virtual GoogleString Name() const { return FormatName(cache_->Name()); }
71  virtual bool IsBlocking() const { return false; }
72 
80  virtual void ShutDown();
81 
86 
87  virtual bool IsHealthy() const {
88  return !stopped_.value() && cache_->IsHealthy();
89  }
90 
91  int32 outstanding_operations() { return outstanding_operations_.value(); }
92 
93  private:
96  void DoGet(GoogleString* key, Callback* callback);
97  void CancelGet(GoogleString* key, Callback* callback);
98 
101  void DoMultiGet(MultiGetRequest* request);
102  void CancelMultiGet(MultiGetRequest* request);
103 
106  void DoPut(GoogleString* key, const SharedString value);
107  void CancelPut(GoogleString* key, const SharedString value);
108  void DoDelete(GoogleString* key);
109  void CancelDelete(GoogleString* key);
110 
111  void MultiGetReportNotFound(MultiGetRequest* request);
112 
113  CacheInterface* cache_;
114  QueuedWorkerPool::Sequence* sequence_;
115  AtomicBool stopped_;
116  AtomicInt32 outstanding_operations_;
117 
118 
119 };
120 
121 }
122 
123 #endif
void CancelPendingOperations()
Definition: async_cache.h:85
virtual void Put(const GoogleString &key, const SharedString &value)
Abstract interface for a cache.
Definition: cache_interface.h:32
virtual bool IsHealthy() const
Definition: async_cache.h:87
virtual void MultiGet(MultiGetRequest *request)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
AsyncCache(CacheInterface *cache, QueuedWorkerPool *pool)
virtual bool IsBlocking() const
Definition: async_cache.h:71
Definition: async_cache.h:39
Definition: queued_worker_pool.h:50
virtual bool IsHealthy() const =0
Definition: shared_string.h:40
Definition: cache_interface.h:42
int32 value() const
Return the value currently stored. Has acquire semantics (see above).
Definition: atomic_int32.h:83
virtual GoogleString Name() const
Definition: async_cache.h:70
virtual GoogleString Name() const =0
void CancelPendingFunctions() LOCKS_EXCLUDED(sequence_mutex_)
Calls Cancel on all pending functions in the queue.
static const int64 kMaxQueueSize
Definition: async_cache.h:53
virtual void ShutDown()
virtual void Get(const GoogleString &key, Callback *callback)