Develop a cache that supports TTL with an active strategy instead of a lazy strategy (or passive). You can read more about lazy vs active removing here.
- The cache should support a string-like type as key and a byte slice as value.
- The code must come with a benchmark (in order to check for the allocations).
- You can't use a
mapor an external library. You must create your own data structure. - The cache functions can't produce more than 1 allocation per operation.
- The cache supports active TTL
The cache should satisfy the following interface:
type Cache interface {
// Set will store the key value pair with a given TTL.
Set(key, value []byte, ttl time.Duration)
// Get returns the value stored using `key`.
//
// If the key is not present value will be set to nil.
Get(key []byte) (value []byte, ttl time.Duration)
}