MemoryCache
Overview
MemoryCache is a memory cache class in swift.
- The MemoryCache class incorporates LRU policies, which ensure that a cache doesn’t use too much of the system’s memory. If memory is needed by other applications, it removes some items from the cache, minimizing its memory footprint.
- You can add, remove, and query items with expiration in the cache from different threads without having to lock the cache yourself. ( thread-safe )
- Unlike the NSCache class, the cache guarantees a type by its key. ( type-safe )
Usage
Basic
Defining keys
Adding a Cached Value
Getting a Cached Value
Removing Cached Values
- Removes the cache of the specified key.
- Removes the cache of the specified key if it expired.
- Removes All.
Others
Properties
Implement delegate
Expiration date
You can specify expiration date for cache. The default expiration is .never
.
Requirements
- Swift 4.2 ~
- Xcode 10.1 ~
Installation
CocoaPods
MemoryCache is available through CocoaPods. To install
it, simply add the following line to your Podfile:
Carthage
You can integrate via Carthage, too.
Add the following line to your Cartfile
:
github "yysskk/MemoryCache"
and run carthage update
Author
Yusuke Morishita
License
MemoryCache
is available under the MIT license. See the LICENSE file for more info.