pinterest / PINCache

Fast, non-deadlocking parallel object cache for iOS, tvOS and OS X
Apache License 2.0
2.66k stars 361 forks source link

Cannot initialize with a TTL memory cache #226

Closed wiseoldduck closed 5 years ago

wiseoldduck commented 6 years ago

- (instancetype)initWithName:(nonnull NSString *)name rootPath:(nonnull NSString *)rootPath serializer:(nullable PINDiskCacheSerializerBlock)serializer deserializer:(nullable PINDiskCacheDeserializerBlock)deserializer keyEncoder:(nullable PINDiskCacheKeyEncoderBlock)keyEncoder keyDecoder:(nullable PINDiskCacheKeyDecoderBlock)keyDecoder ttlCache:(BOOL)ttlCache NS_DESIGNATED_INITIALIZER;

passing ttlCache:YES here only enables ttlCache for the disk cache, the memory cache is still set up as a non-ttl cache.

This can be corrected after the fact with PINMemoryCache: - (void)setTtlCache:(BOOL)ttlCache DEPRECATED_MSG_ATTRIBUTE("ttlCache is no longer a settable property and must now be set via initializer."); but, this is unintuitive, and as you can see this method is marked as deprecated.

internalG commented 5 years ago

Yes, it also happens in sharedCache. The TTL support in latest code is confusing.

mc7h commented 5 years ago

Agreed, it's confusing - I ran into issues once I adopted it - my previous custom cache started deleting the disk cache upon instantiation of the Manager. I think because I hadn't adopted the optional Protocol.

Also, shouldn't there be away to turn on TTL for the shared cache of the default Manager? otherwise it's impossible to get ageLimit working.