Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save crisanvlad/4382bab743dfdc23748cc717cf376d1a to your computer and use it in GitHub Desktop.
Save crisanvlad/4382bab743dfdc23748cc717cf376d1a to your computer and use it in GitHub Desktop.
OSAllocatedUnfairLock
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