Created
June 25, 2025 17:39
-
-
Save crisanvlad/4382bab743dfdc23748cc717cf376d1a to your computer and use it in GitHub Desktop.
OSAllocatedUnfairLock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cache<Key: Hashable, Value> { | |
private let _cache: OSAllocatedUnfairLock<[Key: Value]> | |
init() { | |
_cache = OSAllocatedUnfairLock(initialState: [:]) | |
} | |
func get(_ key: Key) -> Value? { | |
_cache.withLock { cache in | |
cache[key] | |
} | |
} | |
func set(_ key: Key, value: Value) { | |
_cache.withLock { cache in | |
cache[key] = value | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment