package
0.0.0-20240519111142-3e416e18f32e
Repository: https://github.com/snail007/gmc.git
Documentation: pkg.go.dev
# README
GMC Cache
- Support of Redis.
- Support of Multiple redis source.
Configuration
cache configuration section in app.toml
########################################################
# cache configuration
########################################################
# redis supported
# support of mutiple redis server
# notic: each config section must have an unique id
########################################################
[cache]
default="redis"
[[cache.redis]]
debug=true
enable=true
id="default"
address="127.0.0.1:6379"
prefix=""
password=""
# seconds
timeout=10
dbnum=0
maxidle=10
maxactive=30
# seconds
idletimeout=300
# seconds
maxconnlifetime=3600
wait=true
Example
package main
import (
"github.com/snail007/gmc"
"time"
)
func main() {
cfg := gmc.New.Config()
cfg.SetConfigFile("../../app.toml")
err := cfg.ReadInConfig()
if err != nil {
panic(err)
}
// Init only using [cache] section in app.toml
gmc.Cache.Init(cfg)
// cache default is redis in app.toml
// so gmc.Cache() equal to gmc.Redis()
// we can connect to multiple cache drivers at same time, id is the unique name of driver
// gmc.Cache(id) to load `id` named default driver.
c := gmc.Cache.Cache()
c.Set("test", "aaa", time.Second)
c.Get("test")
}
# Packages
No description provided by the author
# Functions
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
File acquires a file cache object associated the id, id default is : `default`.
Init parse app.toml database configuration, `cfg` is Config object of app.toml.
Memory acquires a memory cache object associated the id, id default is : `default`.
NewFileCache creates and returns a new file cache.
No description provided by the author
No description provided by the author
No description provided by the author
NewMemoryCache returns a new cache with a given default expiration duration and cleanup interval.
NewMemoryCacheFrom returns a new cache with a given default expiration duration and cleanup interval.
NewRedisCache returns a new redis cache object.
No description provided by the author
Redis acquires a redis cache object associated the id, id default is : `default`.
No description provided by the author
# Constants
DefaultExpiration for use with functions that take an expiration time.
NoExpiration for use with functions that take an expiration time.
# Variables
ErrKeyNotExists is the error of key not exists.
# Structs
FileCache represents a file cache adapter implementation.
No description provided by the author
Item represents a cache item.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author