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

Data emptying #232

Closed bapidashu closed 5 years ago

bapidashu commented 6 years ago

Hello, Sir I use [PINCache sharedCache] in the APP to cache data. But when I came over and opened the APP for a while, I found that all my cached data had been cleared. [PINCache sharedCache] can cache data on disk and memory, why my data on disk is also cleared? Data emptying

Quanhua-Guan commented 6 years ago

PINDiskCache磁盘缓存默认限制了50M, 超过大小会被自动清理. @bapidashu

bapidashu commented 6 years ago

好的,非常感谢

bapidashu commented 6 years ago

/** The maximum number of bytes allowed on disk. This value is checked every time an object is set, if the written size exceeds the limit a trim call is queued. Defaults to 0.0, meaning no practical limit.

*/ @property (assign) NSUInteger byteLimit;

但是我看他源码说默认是没有限制的啊,那么这个50M是从哪里得来的呢

Quanhua-Guan commented 6 years ago

https://github.com/pinterest/PINCache/blob/master/Source/PINDiskCache.m line 216 @bapidashu

bapidashu commented 6 years ago

好吧,那意思说我如果不需要限制的话,就需要将这个byteLimit 设置为0就好了么

Quanhua-Guan commented 6 years ago

好吧,那意思说我如果不需要限制的话,就需要将这个byteLimit 设置为0就好了么

是的. 当代码是这样的.

garrettmoon commented 5 years ago

Hello, did you solve your issue (sorry, I can't read many Chinese characters)? If you don't want the cache to delete your data you'll want to set an infinite size and time limit. Do note however, this is a cache and the disk cache is stored in your apps cache directory. This means the operating system can delete it at any time.

bapidashu commented 5 years ago

Hello, did you solve your issue (sorry, I can't read many Chinese characters)? If you don't want the cache to delete your data you'll want to set an infinite size and time limit. Do note however, this is a cache and the disk cache is stored in your apps cache directory. This means the operating system can delete it at any time.

Thank you very much for your reply.

Yes, I understand that the cache is cleared. But why is the data stored on the disk also cleared? And every time it's cleared with the cache, it's confusing to me. And I've set the storage size and time to be infinite. I also found this problem on only older models (I used the iPhone6sPlus, and there were some issues with the device's main board). Is this a problem only for a particular device? I haven't found the answer yet.

garrettmoon commented 5 years ago

@bapidashu sorry for the delayed reply. I don't think there are any problems with particular devices, but the it's possible the operating system clears caches on different devices at different times / rates… Could it be that certain devices have less disk space?