Documentation ¶
Index ¶
Constants ¶
View Source
const ( // For use with functions that take an expiration time. NoExpiration time.Duration = -1 // For use with functions that take an expiration time. Equivalent to // passing in the same expiration duration as was given to New() or // NewFrom() when the cache was created (e.g. 5 minutes.) DefaultExpiration time.Duration = 0 // For use with functions that do not clean up. NoCleanup time.Duration = -1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { Set(k string, x interface{}, d time.Duration) SetDefault(k string, x interface{}) Add(k string, x interface{}, d time.Duration) error Get(k string) (interface{}, bool) GetWithExpiration(k string) (interface{}, time.Time, bool) Delete(k string) DeleteExpired() Keys() []string OnEvicted(f func(string, interface{})) Save(w io.Writer) (err error) SaveFile(fname string) error Load(r io.Reader) error LoadFile(fname string) error Items() map[string]Item ItemCount() int Flush() }
func New ¶
Return a new cache with a given default expiration duration and cleanup interval. If the expiration duration is less than one (or NoExpiration), the items in the cache never expire (by default), and must be deleted manually. If the cleanup interval is less than one, expired items are not deleted from the cache before calling c.DeleteExpired().
Click to show internal directories.
Click to hide internal directories.