https://github.com/cozzin/cache
💾 Simple memory & disk cache
https://github.com/cozzin/cache
cache disk-cache ios mac memory-cache swift
Last synced: 4 months ago
JSON representation
💾 Simple memory & disk cache
- Host: GitHub
- URL: https://github.com/cozzin/cache
- Owner: cozzin
- Created: 2021-10-03T07:24:18.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-04-24T12:28:10.000Z (almost 3 years ago)
- Last Synced: 2025-09-08T05:43:19.486Z (5 months 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