https://github.com/0xopenbytes/cache
📦 Simple in-memory key-value store
https://github.com/0xopenbytes/cache
cache data json swift
Last synced: about 2 months ago
JSON representation
📦 Simple in-memory key-value store
- Host: GitHub
- URL: https://github.com/0xopenbytes/cache
- Owner: 0xOpenBytes
- License: mit
- Created: 2023-03-06T23:54:23.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-07T00:39:05.000Z (over 3 years ago)
- Last Synced: 2025-05-13T00:46:04.209Z (about 1 year ago)
- Topics: cache, data, json, swift
- Language: Swift
- Homepage: https://0xopenbytes.github.io/Cache/
- Size: 6.84 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.
```swift
let cache = Cache()
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.
```swift
let cache = Cache()
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.