Skip to content
/ gcache Public

An in-memory K/V cache library. support generic!

License

Notifications You must be signed in to change notification settings

gmodx/gcache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gcache

GoDoc

An golang cache library, support generic.

Installation

go get github.com/gmodx/gcache

Usage

memory cache example

package main

import (
	"fmt"
	"time"

	"github.com/gmodx/gcache/abstract"
	"github.com/gmodx/gcache/memcache"
)

func main() {
	var c abstract.ICache[string] = memcache.New[string](memcache.MemCacheOptions{CleanupInterval: 10 * time.Second})

	// Set a value in the cache with the key "baz" and the value "bar", specifying that it has no expiration.
	c.Set("baz", "bar", abstract.CacheEntryOptions{Expiration: abstract.NoExpiration})

	// Get the value stored in the cache with the key "baz".
	val := c.Get("baz")
	if val != nil {
		fmt.Println(val)
	}

	// Refresh the expiration time of the cached item with the key "baz".
	c.Refresh("baz")

	// Remove the cached item with the key "baz".
	c.Remove("baz")
}

About

An in-memory K/V cache library. support generic!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages