Contents

wegenerlabs/swiftprioritycache

A lightweight, actor-isolated, disk-backed cache written in Swift.

Quick Start

import Foundation
import SwiftPriorityCache

// Create or load a cache with a maximum size of 100 MB
let cache = try SwiftPriorityCache(defaultMaxTotalSize: 100 * 1024 * 1024)

// Example URL and data
let url = URL(string: "https://example.com/data.csv")!
let (data, _) = try await URLSession.shared.data(from: url)

// Save with a given priority (higher = more important)
let saved = try await cache.save(priority: 10, data: data, remoteURL: url)
print("Saved: \(saved)")

// Check if the item is cached
if let localURL = cache.localURL(remoteURL: url) {
    print("Cache URL: \(localURL)")
}

// Clear the cache
try await cache.clear()

Dependencies

License

MIT License

Package Metadata

Repository: wegenerlabs/swiftprioritycache

Default branch: main

README: README.md