Skip to content

Commit cda7a45

Browse files
committed
Updated YYCache bridge with the config property
1 parent 0a96a50 commit cda7a45

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

SDWebImageYYPlugin/Classes/YYCache/YYCacheBridge/YYDiskCache+SDAdditions.h

+2
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@
1111
/// YYDiskCache category to support `SDDiskCache` protocol. This allow user who prefer YYDiskCache to be used as SDWebImage's custom disk cache
1212
@interface YYDiskCache (SDAdditions) <SDDiskCache>
1313

14+
@property (nonatomic, strong, readonly, nullable) SDImageCacheConfig *config;
15+
1416
@end

SDWebImageYYPlugin/Classes/YYCache/YYCacheBridge/YYDiskCache+SDAdditions.m

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@
1010

1111
@interface YYDiskCache ()
1212

13-
@property (nonatomic, strong, nullable) SDImageCacheConfig *sd_config;
14-
1513
// Internal Headers
1614
- (NSString *)_filenameForKey:(NSString *)key;
1715

1816
@end
1917

2018
@implementation YYDiskCache (SDAdditions)
2119

22-
- (SDImageCacheConfig *)sd_config {
23-
return objc_getAssociatedObject(self, @selector(sd_config));
20+
- (SDImageCacheConfig *)config {
21+
return objc_getAssociatedObject(self, @selector(config));
2422
}
2523

26-
- (void)setSd_config:(SDImageCacheConfig *)sd_config {
27-
objc_setAssociatedObject(self, @selector(sd_config), sd_config, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
24+
- (void)setConfig:(SDImageCacheConfig *)config {
25+
objc_setAssociatedObject(self, @selector(config), config, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
2826
}
2927

3028
#pragma mark - SDDiskCache
3129

3230
- (instancetype)initWithCachePath:(NSString *)cachePath config:(SDImageCacheConfig *)config {
3331
self = [self initWithPath:cachePath inlineThreshold:0];
3432
if (self) {
35-
self.sd_config = config;
33+
self.config = config;
34+
self.ageLimit = config.maxDiskAge;
35+
self.costLimit = config.maxDiskSize;
3636
}
3737
return self;
3838
}
@@ -78,8 +78,8 @@ - (void)removeAllData {
7878
}
7979

8080
- (void)removeExpiredData {
81-
NSTimeInterval ageLimit = self.sd_config.maxDiskAge;
82-
NSUInteger sizeLimit = self.sd_config.maxDiskSize;
81+
NSTimeInterval ageLimit = self.config.maxDiskAge;
82+
NSUInteger sizeLimit = self.config.maxDiskSize;
8383

8484
[self trimToAge:ageLimit];
8585
[self trimToCost:sizeLimit];

SDWebImageYYPlugin/Classes/YYCache/YYCacheBridge/YYMemoryCache+SDAdditions.h

+2
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@
1111
/// YYMemoryCache category to support `SDMemoryCache` protocol. This allow user who prefer YYMemoryCache to be used as SDWebImage's custom memory cache
1212
@interface YYMemoryCache (SDAdditions) <SDMemoryCache>
1313

14+
@property (nonatomic, strong, readonly, nullable) SDImageCacheConfig *config;
15+
1416
@end

SDWebImageYYPlugin/Classes/YYCache/YYCacheBridge/YYMemoryCache+SDAdditions.m

+5-11
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,22 @@
88
#import "YYMemoryCache+SDAdditions.h"
99
#import <objc/runtime.h>
1010

11-
@interface YYMemoryCache ()
12-
13-
@property (nonatomic, strong, nullable) SDImageCacheConfig *sd_config;
14-
15-
@end
16-
1711
@implementation YYMemoryCache (SDAdditions)
1812

19-
- (SDImageCacheConfig *)sd_config {
20-
return objc_getAssociatedObject(self, @selector(sd_config));
13+
- (SDImageCacheConfig *)config {
14+
return objc_getAssociatedObject(self, @selector(config));
2115
}
2216

23-
- (void)setSd_config:(SDImageCacheConfig *)sd_config {
24-
objc_setAssociatedObject(self, @selector(sd_config), sd_config, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
17+
- (void)setConfig:(SDImageCacheConfig *)config {
18+
objc_setAssociatedObject(self, @selector(config), config, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
2519
}
2620

2721
#pragma mark - SDMemoryCache
2822

2923
- (instancetype)initWithConfig:(SDImageCacheConfig *)config {
3024
self = [self init];
3125
if (self) {
32-
self.sd_config = config;
26+
self.config = config;
3327
self.countLimit = config.maxMemoryCount;
3428
self.costLimit = config.maxMemoryCost;
3529
}

0 commit comments

Comments
 (0)