go-cache
go-cache is a caching system for Golang with background stale cache regeneration.
tl;dr
Vendor go-cache, then copy the in memory or redis example.
Project Overview
go-cache is separated into:
cacher
- a struct that provides an entry point for getting and expiring keys for a given engine.
engines
- a number of different storage types, including in memory, Redis, and Aerospike.
joque
- a job queue using go routines and channel communication.
As go-cache is a stale cache, once an item has expired, it is not removed from the cache automatically. Instead, it will
continue to return the value currently stored, and recreate the value concurrently. Once processed, it will replace the
existing value, which will be returned by subsequent cache get requests.
An additional time value, cleanupTTL, is passed to the cacher, which is used to remove keys which have expired but not
regenerated by the given time. This stops the cache from becoming full of very old values that may not be used or, when
they are requested, return very stale data.
More details are available via the godoc site:
Getting Started
Prerequisites
Installing
You can install go-cache with your favourite Go vendoring tool:
go get github.com/fresh8/go-cache
Running
For a basic usage example, please see the docs example folder.
Adding Engines
Engines follow a clear interface exposed by
go-cache, so you can create and use your own for whichever backend you desire. Pull requests for new engines are most
definitely welcome and encouraged!
Testing
Prerequisites
Running Local Tests
With glide installed locally, you can use the following command to run all tests, excluding vendors:
go test $(glide nv)