Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package utils

import (
"time"


"github.com/go-kratos/kratos/v2/log"
"github.com/jinzhu/copier"
"github.com/patrickmn/go-cache"
)

var cacheDriver = cache.New(5*time.Minute, 10*time.Minute)

const (
CACHE_EXP_1DAY = time.Hour * 24
)
var cacheDriver = cache.New(1*time.Minute, 10*time.Minute)

func SetGoCache[T any](key string, val T, exp time.Duration) {
cacheDriver.Set(key, val, exp)
Expand All @@ -27,3 +25,13 @@ func GetGoCache[T any](key string, defaultVal T) (T, bool) {
func DelGoCache(key string) {
cacheDriver.Delete(key)
}

func DeepCopy(to, form any) {
err := copier.CopyWithOption(to, form, copier.Option{
IgnoreEmpty: true,
DeepCopy: true,
})
if err != nil {
log.Error(err)
}
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.18

require (
github.com/go-kratos/kratos/v2 v2.5.4
github.com/jinzhu/copier v0.3.5
github.com/jinzhu/now v1.1.5
github.com/json-iterator/go v1.1.12
github.com/panjf2000/ants/v2 v2.7.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0f
github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jinzhu/copier v0.3.5 h1:GlvfUwHk62RokgqVNvYsku0TATCF7bAHVwEXoBh3iJg=
github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Expand Down