OLD | NEW |
(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. This returned |
| 30 // value is guaranteed to be valid until Insert or Clear. |
| 31 // Else return nullptr. |
| 32 V* Lookup(const K& key) { return impl_.Lookup(key); } |
| 33 |
| 34 // Removes all entries from the cache. This method MUST be called before |
| 35 // destruction. |
| 36 void Clear() { impl_.Clear(); } |
| 37 |
| 38 // Returns maximum size of the cache. |
| 39 int64_t MaxSize() const { return impl_.MaxSize(); } |
| 40 |
| 41 // Returns current size of the cache. |
| 42 int64_t Size() const { return impl_.Size(); } |
| 43 |
| 44 private: |
| 45 QuicLRUCacheImpl<K, V> impl_; |
| 46 |
| 47 DISALLOW_COPY_AND_ASSIGN(QuicLRUCache); |
| 48 }; |
| 49 |
| 50 } // namespace net |
| 51 |
| 52 #endif // NET_QUIC_PLATFORM_API_QUIC_LRU_CACHE_H_ |
OLD | NEW |