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

Side by Side Diff: net/quic/platform/api/quic_lru_cache.h

Issue 2603843002: Add QuicLRUCache. (Closed)
Patch Set: fix Created 3 years, 12 months 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef NET_QUIC_PLATFORM_API_QUIC_LRU_CACHE_H_
6 #define NET_QUIC_PLATFORM_API_QUIC_LRU_CACHE_H_
7
8 #include <memory>
9
10 #include "net/quic/platform/impl/quic_lru_cache_impl.h"
11
12 namespace net {
13
14 // A LRU cache that maps from type Key to Value* in QUIC.
15 // This cache CANNOT be shared by multiple threads (even with locks) because
16 // Value* returned by Lookup() can be invalid if the entry is evicted by other
17 // threads.
18 template <class K, class V>
19 class QuicLRUCache {
20 public:
21 explicit QuicLRUCache(int64_t total_units) : impl_(total_units) {}
22
23 // Inserts one unit of |key|, |value| pair to the cache. Cache takes ownership
24 // of inserted |value|.
25 void Insert(const K& key, std::unique_ptr<V> value) {
26 impl_.Insert(key, std::move(value));
27 }
28
29 // If cache contains an entry for |key|, return a pointer to it.
30 // Else return nullptr.
31 V* Lookup(const K& key) { return impl_.Lookup(key); }
32
33 // Removes all entries from the cache. This method MUST be called before
34 // destruction.
35 void Clear() { impl_.Clear(); }
36
37 // Returns maximum size of the cache.
38 int64_t MaxSize() const { return impl_.MaxSize(); }
39
40 // Returns current size of the cache.
41 int64_t Size() const { return impl_.Size(); }
42
43 private:
44 QuicLRUCacheImpl<K, V> impl_;
45
46 DISALLOW_COPY_AND_ASSIGN(QuicLRUCache);
47 };
48
49 } // namespace net
50
51 #endif // NET_QUIC_PLATFORM_API_QUIC_LRU_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698