From ef44274f0efb7ebc3141e643e4374bb32e3945f9 Mon Sep 17 00:00:00 2001 From: Reza Date: Wed, 29 Nov 2023 17:49:48 +0100 Subject: [PATCH] fix cache --- lib/cache/drivers/memory/memory.go | 4 ++++ lib/cache/drivers/redis/redis.go | 4 ++++ lib/cache/functions.go | 4 ++++ lib/cache/interface.go | 3 +++ 4 files changed, 15 insertions(+) diff --git a/lib/cache/drivers/memory/memory.go b/lib/cache/drivers/memory/memory.go index 90176528..048cf59a 100644 --- a/lib/cache/drivers/memory/memory.go +++ b/lib/cache/drivers/memory/memory.go @@ -15,6 +15,10 @@ var unmarshaller func(bytes []byte, out interface{}) error = binary.Unmarshal type driver struct{} +func (d driver) SetPrefix(p string) { + return +} + var items sync.Map func (driver) Register() error { diff --git a/lib/cache/drivers/redis/redis.go b/lib/cache/drivers/redis/redis.go index 1a70a045..b5b4254c 100644 --- a/lib/cache/drivers/redis/redis.go +++ b/lib/cache/drivers/redis/redis.go @@ -242,3 +242,7 @@ func toInt64(n interface{}) int64 { } return 0 } + +func (d driver) SetPrefix(p string) { + prefix = p +} diff --git a/lib/cache/functions.go b/lib/cache/functions.go index 9204024c..c3a6b561 100644 --- a/lib/cache/functions.go +++ b/lib/cache/functions.go @@ -133,3 +133,7 @@ func Register() error { func DefaultDriver() Interface { return defaultDriver } + +func SetPrefix(prefix string) { + defaultDriver.SetPrefix(prefix) +} diff --git a/lib/cache/interface.go b/lib/cache/interface.go index b325647c..040526c0 100644 --- a/lib/cache/interface.go +++ b/lib/cache/interface.go @@ -71,4 +71,7 @@ type Interface interface { // SetUnMarshaller set []byte to interface{} unmarshalling function SetUnMarshaller(func(bytes []byte, out interface{}) error) + + // SetPrefix set a key prefix + SetPrefix(p string) }