Junior — Senior
Local cache to reduce latency when working with remote key-value storage
livecode
Task condition
The system uses an interface to access a key-value database located in the USA, while the client side operates in Europe. The large geographical distance causes noticeable delays with each database request. To speed up the response, a caching layer needs to be implemented. For this, the 'Decorator' pattern should be applied, which will wrap the original interface implementation and hide a local cache inside.
Type KVDatabase interface {
Get(string) (string, error)
GetKeys() ([]string, error)
}
Type RedisDatabase struct {
// ...
}
func (d *RedisDatabase) Get(key string) (string, error) {
// ...
}
func (d *RedisDatabase) GetKeys() ([]string, error) {
// ...
}