Memory cache crash
Closed this issue · 0 comments
mojidabckuu commented
- (id)objectForKey:(NSString *)key expires:(NSDate *)expires withContent:(id(^)())content
{
CKCacheContent *cacheContent = [self objectInMemoryForKey:key];
if (cacheContent == nil && content != nil) {
id object = content();
if (object != nil) {
cacheContent = [CKCacheContent cacheContentWithObject:object expires:expires];
[_internalCache setObject:cacheContent forKey:key];
}
}
return cacheContent.object;
}
- (id)objectInMemoryForKey:(NSString *)key
{
CKCacheContent *cacheContent = [_internalCache objectForKey:key];
if (cacheContent.expires.timeIntervalSinceNow < 0.0) {
[_internalCache removeObjectForKey:key];
cacheContent = nil;
}
return cacheContent.object;
}
When I try to extract value from the cache it gives crash because inside - (id)objectInMemoryForKey:(NSString *)key
you return id
object and then in - (id)objectForKey:(NSString *)key expires:(NSDate *)expires withContent:(id(^)())content
use it like CKCacheContent
.