Merge pull request #2299 from dreampiggy/feature_cache_namespace_prefix

Add the ability to custom the cache namespace prefix
This commit is contained in:
Bogdan Poplauschi 2018-04-24 08:57:43 +03:00 committed by GitHub
commit e8ce9e89c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View File

@ -59,7 +59,11 @@
diskCacheDirectory:(nonnull NSString *)directory
config:(nullable SDImageCacheConfig *)config {
if ((self = [super init])) {
NSString *fullNamespace = [@"com.hackemist.SDImageCache." stringByAppendingString:ns];
NSString *namespacePrefix = config.namespacePrefix;
if (!namespacePrefix) {
namespacePrefix = @"";
}
NSString *fullNamespace = [namespacePrefix stringByAppendingString:ns];
// Create IO serial queue
_ioQueue = dispatch_queue_create("com.hackemist.SDImageCache", DISPATCH_QUEUE_SERIAL);

View File

@ -72,6 +72,12 @@
*/
@property (assign, nonatomic) NSUInteger maxMemoryCount;
/**
* The namespace prefix of cache. It's used to prefix the namespace you provide to the caches's initializer. You 'd better name it with reverse domain name notation and keep the final dot.
* Defautls to `com.hackemist.SDImageCache.`, which will prefix your namespace such as `default` to final `com.hackemist.SDImageCache.default`. If you specify nil, it will be treated equals to an empty string.
*/
@property (copy, nonatomic, nullable) NSString *namespacePrefix;
/**
* The custom file manager for disk cache. Pass nil to let disk cache choose the proper file manager.
* Defaults to nil.

View File

@ -32,6 +32,7 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
_diskCacheWritingOptions = NSDataWritingAtomic;
_maxCacheAge = kDefaultCacheMaxCacheAge;
_maxCacheSize = 0;
_namespacePrefix = @"com.hackemist.SDImageCache.";
_memoryCacheClass = [SDMemoryCache class];
_diskCacheClass = [SDDiskCache class];
}
@ -49,6 +50,7 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
config.maxCacheSize = self.maxCacheSize;
config.maxMemoryCost = self.maxMemoryCost;
config.maxMemoryCount = self.maxMemoryCount;
config.namespacePrefix = [self.namespacePrefix copyWithZone:zone];
config.fileManager = self.fileManager; // NSFileManager does not conform to NSCopying, just pass the reference
config.memoryCacheClass = self.memoryCacheClass;
config.diskCacheClass = self.diskCacheClass;