c := lru.NewLRUCacheString(1234)
onMiss := func(k string) (Cacheable, bool) {
//load from db
return cacheableInt(1), true
}
c.OnMiss(onMiss) // if set
Then, optionally, define a type that implements some of the interfaces:
type cacheableInt int
func (i cacheableInt) OnPurge(why lru.PurgeReason) {
fmt.Printf("Purging %d\n", i)
}
Finally:
for i := 0; i < 2000; i++ {
c.Set(strconv.Itoa(i), cacheableInt(i))
}
This will generate the following output:
Purging 0
Purging 1
...
Purging 764
Purging 765
0studio/lru
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
lru cache for golang
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published