LRUCache is an open-source replacement for NSCache
that behaves in a predictable, debuggable way. LRUCache is an LRU (Least-Recently-Used) cache, meaning that objects will be discarded oldest-first based on the last time they were accessed. LRUCache will automatically empty itself in the event of a memory warning.
LRUCache is packaged as a dynamic framework that you can import into your Xcode project. You can install this manually, or by using Swift Package Manager.
Note: LRUCache requires Xcode 13+ to build, and runs on iOS 11+.
To install using Swift Package Manage, add this to the dependencies:
section in your Package.swift file:
.package(url: "https://github.com/colddream/LRUCache", .upToNextMinor(from: "1.0.0")),
You can create an instance of LRUCache as follows:
let cache = LRUCache<String, Int>(capacity: capacity)
This would create a cache of unlimited size, containing Int
values keyed by String
. To add a value to the cache, use:
cache.set(value: 11, for: "Key1")
To fetch a cached value, use:
let value = cache.getValue(for: "Key1") // Returns nil if value not found
And you can remove all values at once with:
cache.removeAll()
link |
Stars: 0 |
Last commit: 1 year ago |
Full Changelog: https://github.com/colddream/LRUCache/commits/1.0.0
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics