The iOS framework that grows only as fast as its documentation
NIInMemoryCache.h
1 //
2 // Copyright 2011-2014 NimbusKit
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #import <Foundation/Foundation.h>
18 
19 #import "NIPreprocessorMacros.h"
20 
38 @interface NIMemoryCache : NSObject
39 
40 // Designated initializer.
41 - (id)initWithCapacity:(NSUInteger)capacity;
42 
43 - (NSUInteger)count;
44 
45 - (void)storeObject:(id)object withName:(NSString *)name;
46 - (void)storeObject:(id)object withName:(NSString *)name expiresAfter:(NSDate *)expirationDate;
47 
48 - (void)removeObjectWithName:(NSString *)name;
49 - (void)removeAllObjectsWithPrefix:(NSString *)prefix;
50 - (void)removeAllObjects;
51 
52 - (id)objectWithName:(NSString *)name;
53 - (BOOL)containsObjectWithName:(NSString *)name;
54 - (NSDate *)dateOfLastAccessWithName:(NSString *)name;
55 
56 - (NSString *)nameOfLeastRecentlyUsedObject;
57 - (NSString *)nameOfMostRecentlyUsedObject;
58 
59 - (void)reduceMemoryUsage;
60 
61 // Subclassing
62 
63 - (BOOL)shouldSetObject:(id)object withName:(NSString *)name previousObject:(id)previousObject;
64 - (void)didSetObject:(id)object withName:(NSString *)name;
65 - (void)willRemoveObject:(id)object withName:(NSString *)name;
66 
67 // Deprecated method. Use shouldSetObject:withName:previousObject: instead.
68 - (BOOL)willSetObject:(id)object withName:(NSString *)name previousObject:(id)previousObject __NI_DEPRECATED_METHOD;
69 
70 @end
71 
92 
93 @property (nonatomic, readonly) unsigned long long numberOfPixels;
94 
95 @property (nonatomic) unsigned long long maxNumberOfPixels; // Default: 0 (unlimited)
96 @property (nonatomic) unsigned long long maxNumberOfPixelsUnderStress; // Default: 0 (unlimited)
97 
98 @end
99 // End of In-Memory Cache //////////////////////////////////////////////////////////////////
101 
286 // NIImageMemoryCache
287 
void removeAllObjects()
Removes all objects from the cache, regardless of expiration dates.
An in-memory cache for storing objects with expiration support.
void reduceMemoryUsage()
Removes all expired objects from the cache.
An in-memory cache for storing images with caps on the total number of pixels.
unsigned long long numberOfPixels
Returns the total number of pixels being stored in the cache.
NSString * nameOfMostRecentlyUsedObject()
Retrieve the key with the most fresh access.
unsigned long long maxNumberOfPixelsUnderStress
The maximum number of pixels this cache may store after a call to reduceMemoryUsage.
NSUInteger count()
Returns the number of objects currently in the cache.
unsigned long long maxNumberOfPixels
The maximum number of pixels this cache may ever store.
NSString * nameOfLeastRecentlyUsedObject()
Retrieve the name of the object that was least recently used.