MBFilesystemCache Class Reference
| Inherits from | MBThreadsafeCache : NSObject |
|---|---|
| Conforms to | MBFilesystemCacheDelegate |
| Declared in | MBFilesystemCache.h |
Overview
An object cache implementation capable of persisting cache objects to the filesystem.
Utilize the methods provided by the MBThreadsafeCache superclass to access
data stored in an MBFilesystemCache if you do not care whether or not a
cache object is loaded into memory when it is requested.
Note: Classes that wish to subclass MBFilesystemCache should refer
to the internal MBFilesystemCache(ForSubclassEyesOnly) methods
declared in the header file MBFilesystemCache+Subclassing.h.
Object lifecycle
– initWithName:
Initializes the receiver with the given name.
- (nonnull instancetype)initWithName:(nonnull NSString *)nameParameters
name |
The name of the filesystem cache. Must not be |
|---|
Return Value
The receiver.
Discussion
The receiver will act as its own delegate unless the cacheDelegate property
is explicitly set.
Warning: Do not use the same cache name for more than one MBFilesystemCache
at any given time. Unpredictable results will occur if you do.
Declared In
MBFilesystemCache.h
– initWithName:cacheDelegate:
Initializes the receiver with the given name.
- (nonnull instancetype)initWithName:(nonnull NSString *)name cacheDelegate:(nonnull id)delegateParameters
name |
The name of the filesystem cache. Must not be |
|---|---|
delegate |
The |
Return Value
The receiver.
Discussion
Warning: Do not use the same cache name for more than one MBFilesystemCache
at any given time. Unpredictable results will occur if you do.
Declared In
MBFilesystemCache.h
Cache properties
readQueue
Returns the operation queue that will be used for performing filesystem cache read operations.
@property (nonnull, nonatomic, readonly) MBCacheReadQueue *readQueueDeclared In
MBFilesystemCache.h
writeQueue
Returns the operation queue that will be used for performing filesystem cache write operations.
@property (nonnull, nonatomic, readonly) MBCacheWriteQueue *writeQueueDeclared In
MBFilesystemCache.h
cacheName
Returns the name of the cache, which is used to determine the directory in which cache files are stored. This is name provided when the receiver is initialized.
@property (nonnull, nonatomic, readonly) NSString *cacheNameDeclared In
MBFilesystemCache.h
cacheDelegate
Returns the MBFilesystemCacheDelegate used by the receiver.
@property (nullable, nonatomic, weak) id cacheDelegateDeclared In
MBFilesystemCache.h
maxAgeOfCacheFiles
Returns the maximum age of the files in the cache, in seconds. Files that
are older than this value will not be used by the cache and will
eventually be deleted. This defaults to the value of the constant
kMBFilesystemCacheDefaultMaxAge (currently, 36 hours).
@property (nonatomic, assign) NSTimeInterval maxAgeOfCacheFilesDeclared In
MBFilesystemCache.h
Checking for objects in the cache
– isKeyInCache:
Determines whether the specified cache key represents an object currently in the cache.
- (BOOL)isKeyInCache:(nonnull id)keyParameters
key |
The cache key to check. |
|---|
Return Value
YES if there is an object associated with key in either the
filesystem or the memory cache; NO otherwise.
Discussion
The filesystem cache and memory cache are both checked for the presence of an object with the specified key.
Declared In
MBFilesystemCache.h
– isKeyInMemoryCache:
Determines whether the specified cache key represents an object currently in the memory cache.
- (BOOL)isKeyInMemoryCache:(nonnull id)keyParameters
key |
The cache key to check. |
|---|
Return Value
YES if there is an object associated with key in the memory
cache; NO otherwise.
Declared In
MBFilesystemCache.h
– isKeyInFilesystemCache:
Determines whether the specified cache key represents an object currently in the filesystem cache.
- (BOOL)isKeyInFilesystemCache:(nonnull id)keyParameters
key |
The cache key to check. |
|---|
Return Value
YES if there is an object associated with key in the filesystem
cache; NO otherwise.
Declared In
MBFilesystemCache.h
Retrieving objects from the cache
– objectForKeyInMemoryCache:
Retrieves an object from the memory cache, if it is there.
- (nullable id)objectForKeyInMemoryCache:(nonnull id)keyParameters
key |
The cache key of the object to retrieve. |
|---|
Return Value
The object instance, or nil if it was not in the cache.
Discussion
Note: This method does not attempt to load an object from the
filesystem cache. Use the objectForKey: method (declared by
the MBThreadsafeCache superclass) to retrieve objects regardless
of whether they’re in the memory or filesystem caches.
Declared In
MBFilesystemCache.h
Managing the filesystem cache
– clearFilesystemCache
Deletes all of the cache objects currently in the filesystem cache.
- (void)clearFilesystemCacheDiscussion
The memory cache is not affected by calls to this method.
Declared In
MBFilesystemCache.h
– purgeCacheFilesOlderThan:
Deletes all cache files older than a certain age.
- (void)purgeCacheFilesOlderThan:(NSTimeInterval)ageInSecondsParameters
ageInSeconds |
The maximum age allowed for cache files. Files older than this age will be deleted. |
|---|
Discussion
The memory cache is not affected by calls to this method.
Declared In
MBFilesystemCache.h
– purgeOutOfDateCacheFiles
Deletes all cache files older than the number of seconds specified by the
maxAgeOfCacheFiles property.
- (void)purgeOutOfDateCacheFilesDiscussion
The memory cache is not affected by calls to this method.
Declared In
MBFilesystemCache.h