Skip to content

go-think/cache

Repository files navigation

Think Cache

Think Cache is a cache library for Golang,it currently supports redis, memory, and can customize the store adapter.

Installation

go get -u github.com/go-think/cache

Usage

Basic Usage

import (
	"github.com/go-think/cache"
	"time"
)


var foo string 

// Create a cache with memory store
c, _ := cache.Cache(cache.NewMemoryStore("thinkgo"))

// Set the value
c.Put("foo", "thinkgo", 10 * time.Minute)

// Get the string associated with the key "foo" from the cache
c.Get("foo", &foo)

Retrieve & Store

Sometimes you may wish to retrieve an item from the cache, but also store a default value if the requested item doesn't exist. For example, you may wish to retrieve all users from the cache or, if they don't exist, retrieve them from the callback and add them to the cache. You may do this using the Remember method:

var foo int

cache.Remember("foo", &a, 1*time.Minute, func() interface{} {
	return "thinkgo"
})

License

This project is licensed under the Apache 2.0 license.

About

A Go caching library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages