OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file contains a template for a Most Recently Used cache that allows | 5 // This file contains a template for a Most Recently Used cache that allows |
6 // constant-time access to items using a key, but easy identification of the | 6 // constant-time access to items using a key, but easy identification of the |
7 // least-recently-used items for removal. Each key can only be associated with | 7 // least-recently-used items for removal. Each key can only be associated with |
8 // one payload item at a time. | 8 // one payload item at a time. |
9 // | 9 // |
10 // The key object will be stored twice, so it should support efficient copying. | 10 // The key object will be stored twice, so it should support efficient copying. |
11 // | 11 // |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 enum { NO_AUTO_EVICT = 0 }; | 51 enum { NO_AUTO_EVICT = 0 }; |
52 | 52 |
53 // The max_size is the size at which the cache will prune its members to when | 53 // The max_size is the size at which the cache will prune its members to when |
54 // a new item is inserted. If the caller wants to manager this itself (for | 54 // a new item is inserted. If the caller wants to manager this itself (for |
55 // example, maybe it has special work to do when something is evicted), it | 55 // example, maybe it has special work to do when something is evicted), it |
56 // can pass NO_AUTO_EVICT to not restrict the cache size. | 56 // can pass NO_AUTO_EVICT to not restrict the cache size. |
57 explicit MRUCacheBase(size_type max_size) : max_size_(max_size) { | 57 explicit MRUCacheBase(size_type max_size) : max_size_(max_size) { |
58 } | 58 } |
59 | 59 |
| 60 MRUCacheBase(size_type max_size, const DeletorType& deletor) |
| 61 : max_size_(max_size), deletor_(deletor) { |
| 62 } |
| 63 |
60 virtual ~MRUCacheBase() { | 64 virtual ~MRUCacheBase() { |
61 iterator i = begin(); | 65 iterator i = begin(); |
62 while (i != end()) | 66 while (i != end()) |
63 i = Erase(i); | 67 i = Erase(i); |
64 } | 68 } |
65 | 69 |
66 // Inserts a payload item with the given key. If an existing item has | 70 // Inserts a payload item with the given key. If an existing item has |
67 // the same key, it is removed prior to insertion. An iterator indicating the | 71 // the same key, it is removed prior to insertion. An iterator indicating the |
68 // inserted item will be returned (this will always be the front of the list). | 72 // inserted item will be returned (this will always be the front of the list). |
69 // | 73 // |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 : ParentType(max_size) { | 248 : ParentType(max_size) { |
245 } | 249 } |
246 virtual ~OwningMRUCache() { | 250 virtual ~OwningMRUCache() { |
247 } | 251 } |
248 | 252 |
249 private: | 253 private: |
250 DISALLOW_COPY_AND_ASSIGN(OwningMRUCache); | 254 DISALLOW_COPY_AND_ASSIGN(OwningMRUCache); |
251 }; | 255 }; |
252 | 256 |
253 #endif // CONTENT_COMMON_MRU_CACHE_H_ | 257 #endif // CONTENT_COMMON_MRU_CACHE_H_ |
OLD | NEW |