// Initialize a cache of size 3 that can hold payload of type V associated with key of type K
// where:
// K = string
// V = string
c := cache.NewCache[string, string](3)
c.Set("key", "value")
c.Get("key") // type *V or nil, if not found
c.Has("key") // boolean
c.Length() // uint
c.Items() // []*Node[K, V]
type Cache[K comparable, V any] struct {
capacity uint
length uint
head *Node[K, V]
}
type Node[K comparable, V any] struct {
key K
payload V
prev *Node[K, V]
next *Node[K, V]
}
// Type Constructor
func NewCache[K comparable, V any](capacity uint) Cache[K, V] {
return Cache[K, V]{
capacity: capacity,
length: 0,
head: nil,
}
}