DiskCache is a disk and file-backed caching library, used in the same way as Redis.
go get github.com/dairoot/diskcachepackage main
import (
"github.com/dairoot/diskcache"
)
funcmain() {
cacheKey:="cache_key"valueStr:="value"cache:=diskcache.NewDiskCache(".cache/")
// Add another item that never expires.cache.Set(cacheKey, valueStr, 0)
// Set the item in the cache if it doesn't already exist.cache.SetNx(cacheKey, valueStr, 0)
// Get the item from the cache.cache.Get(cacheKey)
// Remove the item from the cache.cache.Del(cacheKey)
// Check if the item exists in the cache.cache.Exists(cacheKey)
// Set an item that expires in 60 seconds.cache.Expire(cacheKey, 60)
// Adds a list itemcache.LPush(cacheKey, "xx1")
cache.LPush(cacheKey, "xx2")
cache.LPush(cacheKey, "xx3")
// Removes the specified values from the list stored at keycache.LRem(cacheKey, "xx2")
// Returns the length of the list stored at keycache.LLen(cacheKey)
// Removes and returns the first element of the listcache.LPop(cacheKey)
// Removes and returns the last element of the listcache.RPop(cacheKey)
// Returns elements within the specified interval in the listcache.LRange(cacheKey, 0, 3)
// Adds the specified members to the set stored at keycache.SAdd(cacheKey, "xx1")
cache.SAdd(cacheKey, "xx2")
cache.SAdd(cacheKey, "xx3")
// Removes the specified values from the list stored at keycache.SRem(cacheKey, "xx2")
// Removes and returns one random elements from the set value stored at keycache.SPop(cacheKey)
// Increment the integer value of a key by onecache.Incr(cacheKey)
}