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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/snapshots/lru_cache.h
diff --git a/ios/chrome/browser/snapshots/lru_cache.h b/ios/chrome/browser/snapshots/lru_cache.h
new file mode 100644
index 0000000000000000000000000000000000000000..d0eb2fd36a4491d4febc92126b9004dd6e52f06e
--- /dev/null
+++ b/ios/chrome/browser/snapshots/lru_cache.h
@@ -0,0 +1,62 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef IOS_CHROME_BROWSER_SNAPSHOTS_LRU_CACHE_H_
+#define IOS_CHROME_BROWSER_SNAPSHOTS_LRU_CACHE_H_
+
+#import <Foundation/Foundation.h>
+
+// The LRUCache delegate is called before an item is evicted from the cache.
+@protocol LRUCacheDelegate
+
+- (void)lruCacheWillEvictObject:(id<NSObject>)obj;
sdefresne 2015/11/03 11:25:18 nit: s/obj/object/
jbbegue 2015/11/03 13:37:19 Done.
+
+@end
+
+// This class implements a cache with a limited size. Once the cache reach its
+// size limit, it will start to evict items in a Least Recently Used order
+// (where the term "used" is determined in terms of query to the cache).
+@interface LRUCache : NSObject
+
+// The delegate of the LRUCache called when objects are evicted from the cache.
+@property(nonatomic, assign) id<LRUCacheDelegate> delegate;
+
+// The maximum amount of items that the cache can hold before starting to
+// 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.
+// 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.
+@property(nonatomic, readonly) NSUInteger maxCacheSize;
+
+// Designated initializer, that |maxCacheSize| value is used to specify the
+// maximum amount of items that the cache can hold before starting to evict
+// items.
+- (instancetype)initWithCacheSize:(NSUInteger)maxCacheSize;
sdefresne 2015/11/03 11:25:18 nit: NS_DESIGNATED_INITIALIZER
jbbegue 2015/11/03 13:37:19 Done.
+
+// Query the cache for an item corresponding to the |key|. Returns nil if there
+// is no item corresponding to that key.
+- (id)objectForKey:(id<NSObject>)key;
+
+// 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.
+// property is non zero, the cache may evict an elements if the maximum cache
+// size is reached. If the |key| is already present in the cache, the value for
+// that key is replaced by |obj|. For any evicted object and if the delegate is
+// non nil, it will receive a call to the lruCacheWillEvictObject: selector.
+- (void)setObject:(id<NSObject>)obj forKey:(NSObject*)key;
+
+// Remove the key, value pair corresponding to the given |key|. If the delegate
+// is non nil, it will receive a call to the lruCacheWillEvictObject: selector.
+- (void)removeObjectForKey:(id<NSObject>)key;
+
+// 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.
+// is non nil, it will receive a call to the lruCacheWillEvictObject: selector.
+- (void)removeAllObjects;
+
+// Returns the amount of items that the cache currently hold.
+- (NSUInteger)count;
+
+// Returns true if the cache is empty.
+- (BOOL)isEmpty;
+
+@end
+
+#endif // IOS_CHROME_BROWSER_SNAPSHOTS_LRU_CACHE_H_

Powered by Google App Engine
This is Rietveld 408576698