Cache is a storage for all Item items
type Cache struct { Expiration time.Duration // contains filtered or unexported fields }
▹ Example
func New(expirationTime, cleanupInterval time.Duration) *Cache
New creates a new Cache
func New2(expirationTime, cleanupInterval time.Duration, fn func(key string, value interface{})) *Cache
New2 creates a new Cache with a cleaner function
func (cache *Cache) Add(key string, value interface{}) bool
Add creates an cached item
func (cache *Cache) Clear()
Clear removes all items in the cache
func (cache *Cache) Delete(key string)
Delete deletes a cached item
func (cache *Cache) DeleteAllWithFunc(fn func(key string, value interface{}))
DeleteAllWithFunc does the same like DeleteExpiredWithFunc but not just for the expired items, also the non expired
func (cache *Cache) DeleteExpired()
DeleteExpired checks all cache items and deletes the expired items
func (cache *Cache) DeleteExpiredWithFunc(fn func(key string, value interface{}))
DeleteExpiredWithFunc does the same like DeleteExpired but also calls a function for each deleted item
func (cache *Cache) Export(w io.Writer) error
Export all items to a gob buffer
func (cache *Cache) Get(key string) interface{}
Get returns the value of a cached item or nil if expired
func (cache *Cache) Import(r io.Reader) error
Import all items from a gob buffer
func (cache *Cache) Set(key string, value interface{})
Set creates an Item in the cache, if there is already an item with that name it get overwritten
func (cache *Cache) SetWithDuration(key string, value interface{}, creation time.Time, duration time.Duration)
SetWithDuration does the same as Set but with an specific expiration date
func (cache *Cache) Size() int
Size returns the number of cached items it does not check for expired items, so run DeleteExpired before
func (cache *Cache) String() string
String returns all cached values as string (for debugging)
func (cache *Cache) Time(key string) time.Time
Time returns the creation date of a cached item
func (cache *Cache) Update(key string, value interface{}) bool
Update changes the value of an key. If the key doesn't exist, it returns false
Item as a single object with an interface as value and two time.Time values for creation and expiration dates
type Item struct { Object interface{} Creation time.Time Expiration time.Time }