When exactly do things get removed from urlcache's memory and disk?

半世苍凉 提交于 2019-11-29 11:47:31

Short answer:

The memory cache is lost when the app terminates (or, likely, under memory pressure, too). The disk cache persists across multiple invocations of the app, though can be removed if the device runs out of persistent storage and the OS reclaims space from caches and temp folders.


Long answer:

You ask:

Is it correct to say, every time you force quit or your app crashes due to a memory warning/issue your cache will get flushed, though it leaves your disk intact?

Largely. It may be more precise to say simply that all memory related to your app is discarded when the app terminates and that only those items saved to persistent storage can be retrieved when the app restarts.

Any other place where cache can get flushed out of memory?

You lose everything in the memory cache when the app terminates. There are obviously a few other situations in which case items can be removed:

  • If you manually remove responses from the URLCache.
  • Older, individual items are removed from the cache as you approach the max capacity of the cache and you try to add new items, forcing older items out.
  • Network responses often include a cache policy (indicating how long the response can be safely cached), so it's likely that they're removed at that point.
  • The memory cache may reasonably be purged upon memory pressure (e.g. .UIApplicationDidReceiveMemoryWarning).

When can things stored in disk get removed?

The logic is largely the same as prior point, except that (a) it can survive across invocations of the app); and (b) it's not flushed upon memory pressure, though it can be removed when the device runs low on persistent storage.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!