NSCache emptied when app enters background

前端 未结 1 1374
我在风中等你
我在风中等你 2021-01-12 14:49

I currently use a Subclass of NSCache to store some images (values) with their corresponding names (Keys) and it seems to work fine, when the app is in the foreground. Howev

1条回答
  •  伪装坚强ぢ
    2021-01-12 15:08

    Think you need to ensure that objects placed in cache conform to NSDiscardableContentProtocol to have desired results. From the NSCache Class Reference:

    A common data type stored in NSCache objects is an object that implements the NSDiscardableContent protocol. Storing this type of object in a cache has benefits, because its content can be discarded when it is not needed anymore, thus saving memory. By default, NSDiscardableContent objects in the cache are automatically removed from the cache if their content is discarded, although this automatic removal policy can be changed. If an NSDiscardableContent object is put into the cache, the cache calls discardContentIfPossible on it upon its removal.

    0 讨论(0)
提交回复
热议问题