~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/pagespeed/kernel/cache/delay_cache.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
17
 
// Author: jmarantz@google.com (Joshua Marantz)
18
 
//
19
 
// Contains DelayCache, which wraps a cache, but lets a test delay
20
 
// responses for specific cache-keys.  The callbacks are awakened
21
 
// by an explicit ReleaseKey API.
22
 
//
23
 
// By default, all cache lookups are transmitted immediately to
24
 
// the callback.
25
 
//
26
 
// Note: MockTimeCache also supports delayed callbacks, but they are all delayed
27
 
// by a fixed time.
28
 
 
29
 
#ifndef PAGESPEED_KERNEL_CACHE_DELAY_CACHE_H_
30
 
#define PAGESPEED_KERNEL_CACHE_DELAY_CACHE_H_
31
 
 
32
 
#include <map>
33
 
 
34
 
#include "pagespeed/kernel/base/basictypes.h"
35
 
#include "pagespeed/kernel/base/scoped_ptr.h"
36
 
#include "pagespeed/kernel/base/string.h"
37
 
#include "pagespeed/kernel/base/string_util.h"
38
 
#include "pagespeed/kernel/cache/cache_interface.h"
39
 
#include "pagespeed/kernel/thread/queued_worker_pool.h"
40
 
 
41
 
namespace net_instaweb {
42
 
 
43
 
class AbstractMutex;
44
 
class SharedString;
45
 
class ThreadSystem;
46
 
 
47
 
// See file comment
48
 
class DelayCache : public CacheInterface {
49
 
 public:
50
 
  // Note: takes ownership of nothing.
51
 
  DelayCache(CacheInterface* cache, ThreadSystem* thread_system);
52
 
  virtual ~DelayCache();
53
 
 
54
 
  // Reimplementations of CacheInterface methods.
55
 
  virtual void Get(const GoogleString& key, Callback* callback);
56
 
  virtual void Put(const GoogleString& key, SharedString* value);
57
 
  virtual void Delete(const GoogleString& key);
58
 
  virtual void MultiGet(MultiGetRequest* request);
59
 
 
60
 
  // Instructs the cache to delay delivery of callbacks for specific cache-key.
61
 
  // It is a fatal error -- reported at class destruction, to request delay of
62
 
  // a key that is never looked up and released.
63
 
  void DelayKey(const GoogleString& key);
64
 
 
65
 
  // Release the delay on the callback delivered for a specific key.  It is
66
 
  // ane error to attempt to release a key that was never delayed.
67
 
  void ReleaseKey(const GoogleString& key) { ReleaseKeyInSequence(key, NULL); }
68
 
 
69
 
  // See ReleaseKey.  If sequence is non-NULL, the callback is
70
 
  // delivered on the sequence, otherwise it is delivered directly
71
 
  // from ReleaseKey.
72
 
  void ReleaseKeyInSequence(const GoogleString& key,
73
 
                            QueuedWorkerPool::Sequence* sequence);
74
 
 
75
 
  static GoogleString FormatName(StringPiece name);
76
 
  virtual GoogleString Name() const { return FormatName(cache_->Name()); }
77
 
 
78
 
  virtual bool IsBlocking() const { return false; }
79
 
  virtual bool IsHealthy() const { return cache_->IsHealthy(); }
80
 
  virtual void ShutDown() { cache_->ShutDown(); }
81
 
 
82
 
 private:
83
 
  class DelayCallback;
84
 
  friend class DelayCallback;
85
 
 
86
 
  void LookupComplete(DelayCallback* callback);
87
 
 
88
 
  typedef std::map<GoogleString, DelayCallback*> DelayMap;
89
 
 
90
 
  CacheInterface* cache_;
91
 
  scoped_ptr<AbstractMutex> mutex_;
92
 
  StringSet delay_requests_;
93
 
  DelayMap delay_map_;
94
 
 
95
 
  DISALLOW_COPY_AND_ASSIGN(DelayCache);
96
 
};
97
 
 
98
 
}  // namespace net_instaweb
99
 
 
100
 
#endif  // PAGESPEED_KERNEL_CACHE_DELAY_CACHE_H_