Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(525)

Unified Diff: net/quic/platform/impl/quic_lru_cache_impl.h

Issue 2603843002: Add QuicLRUCache. (Closed)
Patch Set: fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/platform/api/quic_lru_cache_test.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/platform/impl/quic_lru_cache_impl.h
diff --git a/net/quic/platform/impl/quic_lru_cache_impl.h b/net/quic/platform/impl/quic_lru_cache_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..30e1d4e4c2f40a7cc50e3b7f54ec29eae56b73b7
--- /dev/null
+++ b/net/quic/platform/impl/quic_lru_cache_impl.h
@@ -0,0 +1,49 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_QUIC_PLATFORM_IMPL_QUIC_LRU_CACHE_IMPL_H_
+#define NET_QUIC_PLATFORM_IMPL_QUIC_LRU_CACHE_IMPL_H_
+
+#include "base/containers/mru_cache.h"
+
+namespace net {
+
+template <class K, class V>
+class QuicLRUCacheImpl {
+ public:
+ explicit QuicLRUCacheImpl(int64_t total_units) : mru_cache_(total_units) {}
+
+ // Inserts one unit of |key|, |value| pair to the cache.
+ void Insert(const K& key, std::unique_ptr<V> value) {
+ mru_cache_.Put(key, *value);
Ryan Hamilton 2016/12/27 21:57:40 Since value is dereferenced, but not released does
Ryan Hamilton 2016/12/27 23:44:37 Oh, I see. I misunderstood the type of the underly
+ }
+
+ // If cache contains an entry for |key|, return a pointer to it.
+ // Else return nullptr.
+ V* Lookup(const K& key) {
+ auto cached_it = mru_cache_.Get(key);
+ if (cached_it != mru_cache_.end()) {
+ return &cached_it->second;
+ }
+ return nullptr;
+ }
+
+ // Removes all entries from the cache.
+ void Clear() { mru_cache_.Clear(); }
+
+ // Returns maximum size of the cache.
+ int64_t MaxSize() const { return mru_cache_.max_size(); }
+
+ // Returns current size of the cache.
+ int64_t Size() const { return mru_cache_.size(); }
+
+ private:
+ base::MRUCache<K, V> mru_cache_;
+
+ DISALLOW_COPY_AND_ASSIGN(QuicLRUCacheImpl);
+};
+
+} // namespace net
+
+#endif // NET_QUIC_PLATFORM_IMPL_QUIC_LRU_CACHE_IMPL_H_
« no previous file with comments | « net/quic/platform/api/quic_lru_cache_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698