ibireme / YYCache

High performance cache framework for iOS.
MIT License
2.38k stars 511 forks source link

YYDiskCache initWithPath 存储和取值存在问题 #151

Closed Nododo closed 4 years ago

Nododo commented 5 years ago

代码如图:

yycache

zengweijun commented 4 years ago

YYDiskCache实例被释放了,内部这里self被释放掉,在外面保留cache实例才能解决这个问题

- (void)removeObjectForKey:(NSString *)key completed:(void (^)(NSString * _Nonnull))completedBlock { __weak typeof(self) _self = self; dispatch_async(_queue, ^{ __strong typeof(_self) self = _self; // 这里self是nil,并没有执行后边的逻辑 [self removeObjectForKey:key]; if (completedBlock) completedBlock(key); }); }

gengcong1991 commented 4 years ago

我也遇到这个问题了,求作者解答下

Nododo commented 4 years ago

我也遇到这个问题了,求作者解答下

https://github.com/ibireme/YYCache/issues/151#issuecomment-567010958

zengweijun commented 4 years ago

在外面保存一下cache的实例,也可以直接使用单例对象

曾维俊

邮箱:niuszeng@163.com |

签名由 网易邮箱大师 定制

在2020年04月21日 13:41,一个小朋友 写道:

我也遇到这个问题了,求作者解答下

151 (comment)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.