Skip to content

1.4.0

Compare
Choose a tag to compare
@0xLeif 0xLeif released this 10 Jun 21:22
· 10 commits to main since this release
e8bb8f8

PersistableCache

The PersistableCache class is a cache that stores its contents persistently on disk using a JSON file. Use it to create a cache that persists its contents between application launches. The cache contents are automatically loaded from disk when initialized, and can be saved manually whenever required.

To use PersistableCache, make sure that the specified key type conforms to both RawRepresentable and Hashable protocols. The RawValue of Key must be a String type.

Here's an example of creating a cache, setting a value, and saving it to disk:

let cache = PersistableCache<String, Double>()

cache["pi"] = Double.pi

do {
    try cache.save()
} catch {
    print("Failed to save cache: \(error)")
}

You can also load a previously saved cache from disk:

let cache = PersistableCache<String, Double>()

let pi = cache["pi"] // pi == Double.pi

Remember that the save() function may throw errors if the encoder fails to serialize the cache to JSON or the disk write operation fails. Make sure to handle the errors appropriately.


What's Changed

Full Changelog: 1.3.0...1.4.0