Junior — Senior
Custom thread-safe cache with LRU eviction
livecode
Task condition
It is necessary to create a simplified implementation of a service similar to Redis, which will operate in a multithreaded environment. The implementation should ensure safe concurrent access to stored data and include an LRU (Least Recently Used) mechanism for automatic removal of the least frequently used entries.
type ThreadSafeCache interface {
Get(key string) (result string)
Set(key, value string)
}
To ensure thread safety, synchronization (e.g., mutexes) should be used, and a strategy for updating the usage order of elements should be devised to correctly work with the LRU policy during concurrent requests.