Go to file
Zach 356c1005b3
Update JSON.swift
2023-03-06 17:19:37 -07:00
.github/workflows Update GitHub workflows 2023-03-06 16:58:34 -07:00
Sources/Cache Update JSON.swift 2023-03-06 17:19:37 -07:00
Tests/CacheTests init 2023-03-06 16:54:38 -07:00
.gitignore init 2023-03-06 16:54:38 -07:00
LICENSE Create LICENSE 2023-03-06 16:56:11 -07:00
Package.resolved init 2023-03-06 16:54:38 -07:00
Package.swift init 2023-03-06 16:54:38 -07:00
README.md init 2023-03-06 16:54:38 -07:00

README.md

Cache

Cache is a simple in-memory key-value store that provides thread-safe access to its contents. It is used for storing frequently used data that takes time or resources to compute. When a value is added to the cache, it is stored in memory and can be retrieved quickly on subsequent accesses.

Usage

To use the Cache, first create an instance with the desired key and value types. You can then use the set(:forKey:) method to add items to the cache, and the get(:) method to retrieve items from the cache.

let cache = Cache<String, Int>()
cache.set(42, forKey: "answer")
let answer = cache.get("answer") // answer == 42

The Cache also supports removal of items from the cache using the remove(_:) method. To remove all items from the cache, use the clear() method.

let cache = Cache<String, Int>()
cache.set(42, forKey: "answer")
cache.remove("answer")
let answer = cache.get("answer") // answer == nil

Thread Safety

The Cache is designed to be thread-safe, allowing multiple threads to access and modify the cache without the risk of data races.