A simple general use cache written entirely in swift. Anything can be added to the cache as long as it subscribes to the Cacheable
protocol, and anything as a key as long as it subscribes to CacheableKey
protocol.
- Lightweight Caching generic
- Does One Thing & Does It Well
Create a cache
let cache = Cache<String: Data>()
Add an item to a cache
let item = Data()
cache["MyItem"] = item
Get an item from cache
let cachedItem = cache["MyItem"]
Get an item from a url
cache.load(from: someUrl, key: "MyItem") { cachedItem, wasDownload, error in
}
Add an item to a cache
let image = UIImage()
ImageCache.shared["MyItem"] = image
Get an item from cache
let cachedImage = ImageCache.shared["MyItem"]
Setting an image on an image view
imageView.set(url: someUrl)
Downloading images right to cache for later use
let imagePrecher = ImagePrecher()
imagePrecher.get(urls: myUrls) { items, failedUrls in
//Do something
}
pod 'Cacher'
github "MountainBuffalo/Cacher"
If you wish to contribute to Cacher, please submit a pull request!
Cacher is licensed under the MIT License. As such, Casher is free for general usage, and would make an excellent addition to your next swift application!