Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Least Frequently Used eviction strategy #328

Merged
merged 6 commits into from
May 10, 2024

Conversation

andyfinnell
Copy link
Contributor

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.

## 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.
Source/PINCache.m Outdated Show resolved Hide resolved
Source/PINDiskCache.m Outdated Show resolved Hide resolved
@andyfinnell andyfinnell requested a review from rcancro May 2, 2024 20:50
@andyfinnell andyfinnell merged commit 803c069 into pinterest:master May 10, 2024
6 checks passed
@andyfinnell andyfinnell deleted the add-lfu-eviction-strategy branch May 10, 2024 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants