package
0.0.0-20210318024954-d9e4b8ca2e42
Repository: https://github.com/pangpanglabs/goutils.git
Documentation: pkg.go.dev

# README

goutils/cache

Install github.com/pangpanglabs/goutils/cache package.

go get -u github.com/pangpanglabs/goutils/cache

Getting Started

Use cache.Cache interface type

var mycache cache.Cache

Create local cache(use sync.Map as a cache storage):

mycache = cache.Local{ExpireTime: time.Hour * 24}

Create redis cache

redisConn := "redis://127.0.0.1:6379"
mycache = cache.NewRedis(redisConn)
  • default expire time: time.Hour * 24
  • default Converter: JsonConverter

Or, create redis cache with addiotional options:

redisConn := "redis://127.0.0.1:6379"
mycache = cache.NewRedis(redisConn,
        cache.WithExpireTime(time.Hour*3),
        cache.WithGobConverter(),
        func(redis *cache.Redis) {
                // setup additional options
        },
)

If you want to use GobConverter, you have to identify the concrete type of a value using gob.Register() function.

Save to cache:

loadFromCache, err := cache.LoadOrStore(key, &target, func() (interface{}, error) {
        // return your own result
        return "value", nil
})

Delete from cache:

cache.Delete(key)

# Functions

No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author