All Projects → segmentio → Agecache

segmentio / Agecache

An LRU cache with support for max age

Programming Languages

go
31211 projects - #10 most used programming language

agecache

Thread-safe LRU cache supporting expiration and jitter. Supports cache statistics, as well as eviction and expiration callbacks. Differs from some implementations in that OnEviction is only invoked when an entry is removed as a result of the LRU eviction policy - not when you explicitly delete it or when it expires. OnExpiration is available and invoked when an item expires. Expiration can be passively enforced when performing a Get, or actively enforced by iterating over all keys with an interval.

cache := agecache.New(agecache.Config{
	Capacity: 100,
	MaxAge:   70 * time.Minute,
	MinAge:   60 * time.Minute,
	OnExpiration: func(key, value interface{}) {
		// Handle expiration
	},
	OnEviction: func(key, value interface{}) {
		// Handle eviction
	},
})

cache.Set("foo", "bar")

Documentation

Full docs are available on Godoc.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].