Cache
Usage
๐งโ๐ป
Default
let cache = Cache<String>()
try memory.save("MyValue", forKey: "MyKey")
let cached = try cache.value(forKey: "MyKey")
๐
Advanced
You can also use custom object with Codable
struct CustomObject: Codable {
let value: Int
}
let memory = MemoryCache<CustomObject>(countLimit: 100)
let disk = DiskCache<CustomObject>(fileManager: fileManager)
let cache = Cache<CustomObject>(memory: memory, disk: disk)
try cache.save(CustomObject(value: 0), forKey: "MyKey")
let cached = try cache.value(forKey: "MyKey")
โป๏ธ
Flow
Load value
- Load memory cache if available
- Load disk cache if available 2-1. then, save to memory cache if value existed in disk cache
Save value
- Save memory & cache
๐งฐ
Installation
- In your Xcode project, navigate to File > Swift Packages > Add Package Dependancy...
- Paste the following into the URL field: https://github.com/cozzin/Cache