Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
purge_set.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013 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 NET_INSTAWEB_UTIL_PUBLIC_PURGE_SET_H_
20 #define NET_INSTAWEB_UTIL_PUBLIC_PURGE_SET_H_
21 
22 #include <algorithm>
23 #include <cstddef>
24 
30 
31 namespace net_instaweb {
32 
33 
34 
44 class PurgeSet {
45  class InvalidationTimestampHelper;
47 
48  public:
49  typedef Lru::Iterator Iterator;
50 
56  static const int64 kClockSkewAllowanceMs = 10 * Timer::kMinuteMs;
57 
60  static const int64 kInitialTimestampMs = -1;
61 
65  PurgeSet();
66 
67  explicit PurgeSet(size_t max_size);
68  PurgeSet(const PurgeSet& src);
69  ~PurgeSet();
70 
72  void set_max_size(size_t x) { lru_->set_max_bytes_in_cache(x); }
73 
74  PurgeSet& operator=(const PurgeSet& src);
75 
81  bool UpdateGlobalInvalidationTimestampMs(int64 timestamp_ms);
82 
89  bool Put(const GoogleString& key, int64 timestamp_ms);
90 
92  void Merge(const PurgeSet& src);
93 
96  bool IsValid(const GoogleString& key, int64 timestamp_ms) const;
97 
98  int64 global_invalidation_timestamp_ms() const {
99  return global_invalidation_timestamp_ms_;
100  }
101 
102  bool has_global_invalidation_timestamp_ms() const {
103  return global_invalidation_timestamp_ms_ != kInitialTimestampMs;
104  }
105 
106  Iterator Begin() const { return lru_->Begin(); }
107  Iterator End() const { return lru_->End(); }
108 
109  int num_elements() const { return lru_->num_elements(); }
110  void Clear();
111  void Swap(PurgeSet* that);
112 
113  bool Equals(const PurgeSet& that) const;
114  bool empty() const;
115 
116  GoogleString ToString() const;
117 
118  private:
119  class InvalidationTimestampHelper {
120  public:
121  explicit InvalidationTimestampHelper(PurgeSet* purge_set)
122  : purge_set_(purge_set) {
123  }
124 
125  size_t size(int64 value) const {
126  return sizeof(value);
127  }
128  bool Equal(int64 a, int64 b) const {
129  return a == b;
130  }
131 
134  void EvictNotify(int64 evicted_record_timestamp_ms) {
135  purge_set_->EvictNotify(evicted_record_timestamp_ms);
136  }
137 
139  bool ShouldReplace(int64 old_timestamp_ms, int64 new_timestamp_ms) const {
140  return new_timestamp_ms > old_timestamp_ms;
141  }
142 
143  void Swap(InvalidationTimestampHelper* that) {
144  std::swap(purge_set_, that->purge_set_);
145  }
146 
147  private:
148  PurgeSet* purge_set_;
149  };
150 
151  friend class InvalidationTimestampHelper;
152 
153  void EvictNotify(int64 evicted_record_timestamp_ms);
154 
174  bool SanitizeTimestamp(int64* timestamp_ms);
175 
178  int64 global_invalidation_timestamp_ms_;
179 
183  int64 last_invalidation_timestamp_ms_;
184 
185  InvalidationTimestampHelper helper_;
186  scoped_ptr<Lru> lru_;
187 
190 };
191 
192 }
193 
194 #endif
void set_max_size(size_t x)
Call this immediately after construction.
Definition: purge_set.h:72
static const int64 kInitialTimestampMs
Definition: purge_set.h:60
bool UpdateGlobalInvalidationTimestampMs(int64 timestamp_ms)
bool IsValid(const GoogleString &key, int64 timestamp_ms) const
Definition: purge_set.h:44
Definition: lru_cache_base.h:61
bool Put(const GoogleString &key, int64 timestamp_ms)
void Merge(const PurgeSet &src)
Merge two invalidation records.
Definition: lru_cache_base.h:70
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
static const int64 kClockSkewAllowanceMs
Definition: purge_set.h:56