MBFilesystemCache(ForSubclassEyesOnly) Category Reference

Declared in MBFilesystemCache+Subclassing.h

Overview

The class extensions in this header file are intended for internal use only by MBFilesystemCache implementations.

Code external to MBFilesystemCache should never call these methods directly.

File management

– fileManager

Accesses the NSFileManager instance used internally by the cache.

- (nonnull NSFileManager *)fileManager

Return Value

The file manager.

Declared In

MBFilesystemCache+Subclassing.h

– ensureCacheDirectory

Ensures that the cache directory used by the receiver exists. If the directory does not exist, it will be created.

- (void)ensureCacheDirectory

Declared In

MBFilesystemCache+Subclassing.h

– fileExtensionForCacheKey:

Returns the file extension that should be used for the file associated with the given cache key.

- (nonnull NSString *)fileExtensionForCacheKey:(nonnull id)key

Parameters

key

The cache key for which the file extension is sought.

Return Value

The file extension.

Declared In

MBFilesystemCache+Subclassing.h

– filePathForCacheKey:

Returns the file path that should be used for the file associated with the given cache key.

- (nonnull NSString *)filePathForCacheKey:(nonnull id)key

Parameters

key

The cache key for which the file path is sought.

Return Value

The file path.

Declared In

MBFilesystemCache+Subclassing.h

Loading cache objects

– objectFromCacheFile:

Loads the cache object contained in the specified file.

- (nullable id)objectFromCacheFile:(nonnull NSString *)path

Parameters

path

The path of the file to read.

Return Value

The cache object, or nil if it couldn’t be read..

Discussion

The default implementation reads the file into an NSData instance and then returns the result of calling objectFromCacheData: with that NSData.

Subclasses may override this method to provide a more efficient mechanism for reconstituting objects from files.

Declared In

MBFilesystemCache+Subclassing.h

– objectLoaded:forKey:

Notifies the cache that a cache object has been loaded into memory for the given key.

- (void)objectLoaded:(nonnull id)cacheObj forKey:(nonnull id)key

Parameters

cacheObj

The cache object that was loaded.

key

The cache key associated with the cache object.

Discussion

Subclasses should call this method if they provide another mechanism for loading cache objects. For example, a cache that fetches objects via HTTP can call this method when an HTTP request has completed.

Declared In

MBFilesystemCache+Subclassing.h

Storing objects in the cache

– storeObjectInMemoryCacheIfAppropriate:forKey:

Consults the delegate’s shouldStoreObject:forKey:inMemoryCache: method to determine whether the specified object should be stored in the memory cache.

- (void)storeObjectInMemoryCacheIfAppropriate:(nonnull id)cacheObj forKey:(nonnull id)key

Parameters

cacheObj

The object that may be stored in the cache.

key

The cache key to associate with cacheObj if the delegate permits storage in the cache.

Discussion

If the delegate method returns YES, the object will be stored in the cache and associated with the specified key.

Declared In

MBFilesystemCache+Subclassing.h

– storeObjectInFilesystemCacheIfAppropriate:forKey:

Consults the delegate’s shouldStoreObject:forKey:inFilesystemCache: method to determine whether the specified object should be stored in the filesystem cache.

- (void)storeObjectInFilesystemCacheIfAppropriate:(nonnull id)cacheObj forKey:(nonnull id)key

Parameters

cacheObj

The object that may be stored in the cache.

key

The cache key to associate with cacheObj if the delegate permits storage in the cache.

Discussion

If the delegate method returns YES, the object will be stored in the cache and associated with the specified key.

Declared In

MBFilesystemCache+Subclassing.h