Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
Cache used to call core cache methods off of
func (*Cache) Get ¶
Get takes a key for an item in the cache to look up Returns the data associated with that key and an
Example ¶
cache := NewLFU() cache.Insert(1, []byte("user:1:aeb31da42fae09afqld")) // Get key 1 data, _ := cache.Get(1) fmt.Println("Cached data for key 1:", string(reflect.ValueOf(data).Bytes())) // Get a not cached key _, err := cache.Get(42) fmt.Println("Failed get:", err)
Output: Cached data for key 1: user:1:aeb31da42fae09afqld Failed get: Key: 42 not found in cache
func (*Cache) GetLFUItem ¶
func (c *Cache) GetLFUItem() (value interface{}, data interface{})
GetLFUItem returns the key and data of the least frequently updated item in the cache or -1 and nil for not found
func (*Cache) Insert ¶
Insert takes a key and a value to insert into the cache Returns a boolean for successful insert and an error if failed
Example ¶
cache := NewLFU() inserted, _ := cache.Insert(1, []byte("user:1:aeb31da42fae09afqld")) fmt.Println("Inserted:", inserted) // Insert existing key _, err := cache.Insert(1, "boom") fmt.Println("Insert error:", err)
Output: Inserted: true Insert error: Key already exists in cache
Click to show internal directories.
Click to hide internal directories.