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

Side by Side Diff: ios/chrome/browser/snapshots/lru_cache.h

Issue 1410973008: Added an experiment for an LRU snapshot cache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 2015 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 IOS_CHROME_BROWSER_SNAPSHOTS_LRU_CACHE_H_
6 #define IOS_CHROME_BROWSER_SNAPSHOTS_LRU_CACHE_H_
7
8 #import <Foundation/Foundation.h>
9
10 // The LRUCache delegate is called before an item is evicted from the cache.
11 @protocol LRUCacheDelegate
12
13 - (void)lruCacheWillEvictObject:(id<NSObject>)obj;
sdefresne 2015/11/03 11:25:18 nit: s/obj/object/
jbbegue 2015/11/03 13:37:19 Done.
14
15 @end
16
17 // This class implements a cache with a limited size. Once the cache reach its
18 // size limit, it will start to evict items in a Least Recently Used order
19 // (where the term "used" is determined in terms of query to the cache).
20 @interface LRUCache : NSObject
21
22 // The delegate of the LRUCache called when objects are evicted from the cache.
23 @property(nonatomic, assign) id<LRUCacheDelegate> delegate;
24
25 // The maximum amount of items that the cache can hold before starting to
26 // evict. The value 0 is used to signify that the cache can hold an ulimited
sdefresne 2015/11/03 11:25:18 nit: s/ulimited/unlimited/
jbbegue 2015/11/03 13:37:19 Done.
27 // amount of elements (never evict).
sdefresne 2015/11/03 11:25:18 nit: /never evict/i.e. never evicts/
jbbegue 2015/11/03 13:37:19 Done.
28 @property(nonatomic, readonly) NSUInteger maxCacheSize;
29
30 // Designated initializer, that |maxCacheSize| value is used to specify the
31 // maximum amount of items that the cache can hold before starting to evict
32 // items.
33 - (instancetype)initWithCacheSize:(NSUInteger)maxCacheSize;
sdefresne 2015/11/03 11:25:18 nit: NS_DESIGNATED_INITIALIZER
jbbegue 2015/11/03 13:37:19 Done.
34
35 // Query the cache for an item corresponding to the |key|. Returns nil if there
36 // is no item corresponding to that key.
37 - (id)objectForKey:(id<NSObject>)key;
38
39 // Adds the pair |key|, |obj| to the cache. If the value of the maxCacheSize
sdefresne 2015/11/03 11:25:18 nit: s/obj/object/
jbbegue 2015/11/03 13:37:19 Done.
40 // property is non zero, the cache may evict an elements if the maximum cache
41 // size is reached. If the |key| is already present in the cache, the value for
42 // that key is replaced by |obj|. For any evicted object and if the delegate is
43 // non nil, it will receive a call to the lruCacheWillEvictObject: selector.
44 - (void)setObject:(id<NSObject>)obj forKey:(NSObject*)key;
45
46 // Remove the key, value pair corresponding to the given |key|. If the delegate
47 // is non nil, it will receive a call to the lruCacheWillEvictObject: selector.
48 - (void)removeObjectForKey:(id<NSObject>)key;
49
50 // Remove all objects from the cache. For all evicted object and if the delegate
sdefresne 2015/11/03 11:25:19 nit: For all evicted objects and ...
jbbegue 2015/11/03 13:37:19 Done.
51 // is non nil, it will receive a call to the lruCacheWillEvictObject: selector.
52 - (void)removeAllObjects;
53
54 // Returns the amount of items that the cache currently hold.
55 - (NSUInteger)count;
56
57 // Returns true if the cache is empty.
58 - (BOOL)isEmpty;
59
60 @end
61
62 #endif // IOS_CHROME_BROWSER_SNAPSHOTS_LRU_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698