Create a cache in memory like redis or memcached
The solution has achieve this
-
Define a class "CacheInMemory"
-
Expose the methods basic in a cache
- get: Retrieve the value via key
- set: Store the value with key, allows to add an expiration in ms (optional)
- del: Delete any key
- clear: Clear all keys
- keys: List all keys in the store
-
How to handle if has the same key?
Apply the same logic when you work with hashmap collisions, override or apply a list
-
Being in memory, how could you improve performance in terms of space?
Use compresion to store the data
-
If I want to apply this same solution in a distributed system, how should I modify it?
-
Apply consistent hashing to spread the load between servers
-
Vector clock
-
- Consistency: Every read receives the most recent write or an error.
- Availability: Every request receives a (non-error) response, without the guarantee that it contains the most recent write.
- Partition tolerance: The system continues to operate despite an arbitrary number of messages being dropped (or delayed) by the network between nodes.