Package lfucache implements an O(1) LFU cache structure.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2016-06-29 09:31:02 +02:00
check.go nodeList/lastNode -> head/tail 2013-09-10 06:31:38 +02:00
debug.go Debug flag controls checked/unchecked 2013-09-05 15:21:00 +02:00
doc.go Deprecate package 2015-01-05 11:58:44 +01:00
internal_test.go Simplify external interface 2013-08-19 21:59:38 +02:00
lfucache.go Actually deprecate even more 2016-06-29 09:31:02 +02:00
lfucache_test.go Use slice instead of list.List for eviction channels 2013-09-10 05:32:37 +02:00
LICENSE LICENSE 2013-07-27 22:24:06 +02:00
print.go nodeList/lastNode -> head/tail 2013-09-10 06:31:38 +02:00
README.md Deprecate package 2015-01-05 11:58:44 +01:00
release.go Debug flag controls checked/unchecked 2013-09-05 15:21:00 +02:00

DEPRECATION WARNING This package is unmaintained and probably not what you're looking for.

lfucache Build Status

import "github.com/calmh/lfucache"

Package lfucache implements an O(1) LFU cache structure.

This structure is described in the paper "An O(1) algorithm for implementing the LFU cache eviction scheme" by K. Shah, A. Mitra and D. Matani.

It is based on two levels of doubly linked lists and gives O(1) insert, access and delete operations. The cache supports sending evicted items to interested listeners via channels, and manually evicting all cache items matching a criteria. This is useful for example when using the package as a write cache for a database, where items must be written to the backing store on eviction.

The cache structure is not thread safe.

Example

c := lfucache.Create(1024) // The cache will hold up to 1024 items.
c.Access("mykey")          // => nil, false
c.Insert("mykey", 2345)    // => true
v, ok := c.Access("mykey") // => v = interface{}{2345}, ok = true
c.Delete("mykey")          // => true

Documentation

http://godoc.org/github.com/calmh/lfucache

License

MIT