Skip to content

An in memory flexible cache where both key and value are interfaces

License

Notifications You must be signed in to change notification settings

SotirisAlfonsos/gocache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status GoDoc Go Report Card codebeat badge codecov

Go cache

An in memory flexible cache, with lazy eviction, where both key and value are interfaces

Usage

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
}