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

Unified Diff: net/quic/platform/api/quic_lru_cache.h

Issue 2603843002: Add QuicLRUCache. (Closed)
Patch Set: update comment of Lookup 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/core/crypto/quic_compressed_certs_cache.cc ('k') | net/quic/platform/api/quic_lru_cache_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/platform/api/quic_lru_cache.h
diff --git a/net/quic/platform/api/quic_lru_cache.h b/net/quic/platform/api/quic_lru_cache.h
new file mode 100644
index 0000000000000000000000000000000000000000..b7a0623309cfa2c1840af0ee78d27e56e83ce334
--- /dev/null
+++ b/net/quic/platform/api/quic_lru_cache.h
@@ -0,0 +1,52 @@
+// 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_API_QUIC_LRU_CACHE_H_
+#define NET_QUIC_PLATFORM_API_QUIC_LRU_CACHE_H_
+
+#include <memory>
+
+#include "net/quic/platform/impl/quic_lru_cache_impl.h"
+
+namespace net {
+
+// A LRU cache that maps from type Key to Value* in QUIC.
+// This cache CANNOT be shared by multiple threads (even with locks) because
+// Value* returned by Lookup() can be invalid if the entry is evicted by other
+// threads.
+template <class K, class V>
+class QuicLRUCache {
+ public:
+ explicit QuicLRUCache(int64_t total_units) : impl_(total_units) {}
+
+ // Inserts one unit of |key|, |value| pair to the cache. Cache takes ownership
+ // of inserted |value|.
+ void Insert(const K& key, std::unique_ptr<V> value) {
+ impl_.Insert(key, std::move(value));
+ }
+
+ // If cache contains an entry for |key|, return a pointer to it. This returned
+ // value is guaranteed to be valid until Insert or Clear.
+ // Else return nullptr.
+ V* Lookup(const K& key) { return impl_.Lookup(key); }
+
+ // Removes all entries from the cache. This method MUST be called before
+ // destruction.
+ void Clear() { impl_.Clear(); }
+
+ // Returns maximum size of the cache.
+ int64_t MaxSize() const { return impl_.MaxSize(); }
+
+ // Returns current size of the cache.
+ int64_t Size() const { return impl_.Size(); }
+
+ private:
+ QuicLRUCacheImpl<K, V> impl_;
+
+ DISALLOW_COPY_AND_ASSIGN(QuicLRUCache);
+};
+
+} // namespace net
+
+#endif // NET_QUIC_PLATFORM_API_QUIC_LRU_CACHE_H_
« no previous file with comments | « net/quic/core/crypto/quic_compressed_certs_cache.cc ('k') | net/quic/platform/api/quic_lru_cache_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698