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

Add Least Frequently Used eviction strategy #328

Closed andyfinnell closed 4 months ago

andyfinnell commented 4 months ago

Summary

Currently PINCache only offers LRU (least recently used) as an eviction strategy. However, there are some special workloads where LFU (least frequently used) could offer better performance. This PR introduces LFU alongside the existing LRU eviction strategy. The default is still LRU.

There is also some minor renaming to the trimToSizeByDateAsync, trimToSizeByDate, trimToCostByDate, and trimToCostByDateAsync methods, since those now follow the explicit eviction strategy. Old methods remain and work as expected, but are marked deprecated.

Testing

Added some unit tests for both memory and disk caches to verify objects are evicted based on access count when LFU is selected. Ran tests on iOS, tvOS, macOS.