An in memory flexible cache, with lazy eviction, where both key and value are interfaces
As a first step you need to initialise the cache
c := gocache.New(0)
or with one minute expiration
c := gocache.New(1 * time.Minute)
And then all you have to do is implement the Key interface for the key of your cache
type Key interface {
Equals(key Key) bool
}
Example interface implementation
type Key struct {
Value1 string
Value2 string
}
func (k Key) Equals(key gocache.Key) bool {
if key == nil {
return false
}
return k.Value1 == key.(Key).Value1 && k.Value2 == key.(Key).Value2
}