What is the point of using NSPurgeabledata in NSCache?

I read some article about using the NSCache clause, as many have mentioned that it is recommended to use NSPurgeabledata in NSCache. However, I just can’t understand, while NSCache can already supplant its contents when the memory is full, or it has reached the limit of quantity / expense, why do we still need to use NSPurgeabledata here? Isn't that just potentially slower than using the data object that we already have? What advantage can we take here?

+4
source share
1 answer

The account limit and total cost limit are not strictly enforced. That is, when the cache goes to one of its limits, some of its objects can be evicted immediately, later or never, all depending on the details of the cache implementation. So the benefits of using NSPurgeabledata here are: -

Using purge memory, you allow the system to quickly recover memory if necessary, thereby improving performance. Memory marked as purge is not swapped out when it is recovered by the virtual memory system, since paging is a laborious process. Instead, data is discarded, and if necessary later, it will need to be recounted. It works like a locking mechanism, or we can say that it works like synchronization. If data is accessed by one thread, no other thread can access the same until only the first is complete.

+1
source

Source: https://habr.com/ru/post/1499071/


All Articles