Cache

0.1.0

📦 Simple in-memory key-value store
0xOpenBytes/Cache

What's New

0.1.0

2023-03-07T00:39:05Z

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.


Full Changelog: https://github.com/0xLeif/Cache/commits/0.1.0

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.

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

  • c4.0.0
Last updated: Sun Oct 20 2024 00:49:39 GMT-0900 (Hawaii-Aleutian Daylight Time)