Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cozzin/cache
💾 Simple memory & disk cache
https://github.com/cozzin/cache
cache disk-cache ios mac memory-cache swift
Last synced: 2 days ago
JSON representation
💾 Simple memory & disk cache
- Host: GitHub
- URL: https://github.com/cozzin/cache
- Owner: cozzin
- Created: 2021-10-03T07:24:18.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-24T12:28:10.000Z (over 1 year ago)
- Last Synced: 2024-10-17T21:15:49.989Z (21 days ago)
- Topics: cache, disk-cache, ios, mac, memory-cache, swift
- Language: Swift
- Homepage:
- Size: 11.7 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Cache
💾 Simple memory & disk cache
## Usage
### 🧑💻 Default
```swift
let cache = Cache()try memory.save("MyValue", forKey: "MyKey")
let cached = try cache.value(forKey: "MyKey")
```### 🚀 Advanced
You can also use custom object with `Codable`
```swift
struct CustomObject: Codable {
let value: Int
}let memory = MemoryCache(countLimit: 100)
let disk = DiskCache(fileManager: fileManager)
let cache = Cache(memory: memory, disk: disk)try cache.save(CustomObject(value: 0), forKey: "MyKey")
let cached = try cache.value(forKey: "MyKey")
```## ♻️ Flow
### Load value
1. Load memory cache if available
2. Load disk cache if available
2-1. then, save to memory cache if value existed in disk cache### Save value
1. Save memory & cache
## 🧰 Installation
1. In your Xcode project, navigate to File > Swift Packages > Add Package Dependancy...
2. Paste the following into the URL field: https://github.com/cozzin/Cache