Skip to content
/ evcache Public

Package evcache implements a concurrent key-value cache with capacity overflow eviction, item expiry and deduplication.

License

Notifications You must be signed in to change notification settings

mgnsk/evcache

Repository files navigation

evcache

Go Reference Go Report Card

Package evcache implements a concurrent key-value cache with capacity overflow eviction, item expiry and deduplication.

import "github.com/mgnsk/evcache/v3"

Package evcache implements a concurrent key-value cache with capacity overflow eviction, item expiry and deduplication.

Example

c := evcache.New[string, string](10)

// Fetches an existing value or calls the callback to get a new value.
result, err := c.Fetch("key", time.Minute, func() (string, error) {
	// Possibly a very long network call. It only blocks write access to this key.
	// Read access to the key is always non-blocking.
	return "value", nil
})

if err != nil {
    return err
}

// Use the result.
_ = result