Skip to content
/ GoLRU Public

A basic LRU cache written in Go - Just to learn more about the language

License

Notifications You must be signed in to change notification settings

chaulota/GoLRU

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoLRU

A basic LRU cache written in Go

package main

func main() {
 LRU := GoLRU.New(1000)   // empty (keys are of type int)
 LRU.Put(2, "b")          // 2->b
 LRU.Put(1, "x")          // 2->b, 1->x (insertion-order)
 LRU.Put(1, "a")          // 2->b, 1->a (insertion-order)
 LRU.Oldest()             // 2
 LRU.Newest()             // 1
 LRU.SetMaxSize(2000)     // MaxSize <- 2000
 LRU.GetMaxSize()         // 2000
 _, _ = LRU.Get(2)        // b, true
 _, _ = LRU.Get(3)        // nil, false
 _ = LRU.Values()         // []interface {}{"b", "a"} (insertion-order)
 _ = LRU.Keys()           // []interface {}{2, 1} (insertion-order)
 LRU.Remove(1)            // 2->b
 LRU.Clear()              // empty
 LRU.Empty()              // true
 LRU.Size()               // 0
}

About

A basic LRU cache written in Go - Just to learn more about the language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages