Skip to content

Commit

Permalink
feat(cache): update cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jaronnie committed Dec 7, 2024
1 parent 9fa9841 commit dab3694
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
6 changes: 2 additions & 4 deletions cache/redis/node.go → cache/redis.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package redis
package cache

import (
"context"
Expand All @@ -9,8 +9,6 @@ import (
zerocache "github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/redis"
"github.com/zeromicro/go-zero/core/syncx"

"github.com/jzero-io/jzero-contrib/cache"
)

type cacheNode struct {
Expand Down Expand Up @@ -78,7 +76,7 @@ func (c cacheNode) TakeWithExpireCtx(ctx context.Context, val any, key string, q
return c.node.TakeWithExpireCtx(ctx, val, key, query)
}

func NewCacheNode(rds *redis.Redis) cache.Cache {
func NewRedisNode(rds *redis.Redis) Cache {
singleFlights := syncx.NewSingleFlight()
stats := zerocache.NewStat("redis-cache")
node := zerocache.NewNode(rds, singleFlights, stats, errors.New("cache not found"))
Expand Down
8 changes: 3 additions & 5 deletions cache/sync/map.go → cache/sync_map.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sync
package cache

import (
"context"
Expand All @@ -8,8 +8,6 @@ import (
"time"

"github.com/zeromicro/go-zero/core/errorx"

"github.com/jzero-io/jzero-contrib/cache"
)

type (
Expand All @@ -28,8 +26,8 @@ func (sm *syncMap) SetNoExpireCtx(ctx context.Context, key string, val any) erro
return sm.SetCtx(ctx, key, val)
}

// New creates an instance of SyncMap cache driver
func New(errNotFound error) cache.Cache {
// NewSyncMap creates an instance of SyncMap cache driver
func NewSyncMap(errNotFound error) Cache {
return &syncMap{
storage: &sync.Map{},
errNotFound: errNotFound,
Expand Down

0 comments on commit dab3694

Please sign in to comment.