Version: v3.0.0+incompatible Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2017 License: MIT


CircleCI Coverage Status Go Report Card


go-cache is a caching system for Golang with background stale cache regeneration.


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

  • Go 1.8.x

You can install go-cache with your favourite Go vendoring tool:

go get github.com/fresh8/go-cache

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!


  • Glide 0.12.x
Running Local Tests

With glide installed locally, you can use the following command to run all tests, excluding vendors:

go test $(glide nv)


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL