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

Side by Side Diff: net/quic/platform/impl/quic_lru_cache_impl.h

Issue 2603843002: Add QuicLRUCache. (Closed)
Patch Set: update comment of Lookup Created 3 years, 11 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, std::move(value));
20 }
21
22 // If cache contains an entry for |key|, return a pointer to it. This returned
23 // value is guaranteed to be valid until Insert or Clear.
24 // Else return nullptr.
25 V* Lookup(const K& key) {
26 auto cached_it = mru_cache_.Get(key);
27 if (cached_it != mru_cache_.end()) {
28 return cached_it->second.get();
29 }
30 return nullptr;
31 }
32
33 // Removes all entries from the cache.
34 void Clear() { mru_cache_.Clear(); }
35
36 // Returns maximum size of the cache.
37 int64_t MaxSize() const { return mru_cache_.max_size(); }
38
39 // Returns current size of the cache.
40 int64_t Size() const { return mru_cache_.size(); }
41
42 private:
43 base::MRUCache<K, std::unique_ptr<V>> mru_cache_;
44
45 DISALLOW_COPY_AND_ASSIGN(QuicLRUCacheImpl);
46 };
47
48 } // namespace net
49
50 #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