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

Side by Side Diff: net/quic/platform/impl/quic_lru_cache_impl.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
« no previous file with comments | « net/quic/platform/api/quic_lru_cache_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_IMPL_QUIC_LRU_CACHE_IMPL_H_
6 #define NET_QUIC_PLATFORM_IMPL_QUIC_LRU_CACHE_IMPL_H_
7
8 #include "base/containers/mru_cache.h"
9
10 namespace net {
11
12 template <class K, class V>
13 class QuicLRUCacheImpl {
14 public:
15 explicit QuicLRUCacheImpl(int64_t total_units) : mru_cache_(total_units) {}
16
17 // Inserts one unit of |key|, |value| pair to the cache.
18 void Insert(const K& key, std::unique_ptr<V> value) {
19 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
20 }
21
22 // If cache contains an entry for |key|, return a pointer to it.
23 // Else return nullptr.
24 V* Lookup(const K& key) {
25 auto cached_it = mru_cache_.Get(key);
26 if (cached_it != mru_cache_.end()) {
27 return &cached_it->second;
28 }
29 return nullptr;
30 }
31
32 // Removes all entries from the cache.
33 void Clear() { mru_cache_.Clear(); }
34
35 // Returns maximum size of the cache.
36 int64_t MaxSize() const { return mru_cache_.max_size(); }
37
38 // Returns current size of the cache.
39 int64_t Size() const { return mru_cache_.size(); }
40
41 private:
42 base::MRUCache<K, V> mru_cache_;
43
44 DISALLOW_COPY_AND_ASSIGN(QuicLRUCacheImpl);
45 };
46
47 } // namespace net
48
49 #endif // NET_QUIC_PLATFORM_IMPL_QUIC_LRU_CACHE_IMPL_H_
OLDNEW
« 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