From 99a985586c1597519085185821a5000ddcd94898 Mon Sep 17 00:00:00 2001 From: Yun Date: Mon, 20 May 2024 22:23:38 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=93=E6=9E=84=E4=BD=93=E6=94=B9=E5=A4=A7?= =?UTF-8?q?=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cachex.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cachex.go b/cachex.go index 16f85b3..7d1ed0f 100644 --- a/cachex.go +++ b/cachex.go @@ -11,7 +11,7 @@ import ( // 1.全局单实例 // 到设定的点就删除 -type cache struct { +type Cache struct { store sync.Map } @@ -23,9 +23,9 @@ type cacheData struct { var ErrorEmpty error = errors.New("empty cache") -func NewCache() *cache { +func NewCache() *Cache { - c := &cache{} + c := &Cache{} go func() { for { @@ -43,7 +43,7 @@ func NewCache() *cache { } // 设置缓存 -func (c *cache) Set(key string, value interface{}, expire time.Duration) { +func (c *Cache) Set(key string, value interface{}, expire time.Duration) { if expire == 0 { expire = time.Hour * 24 * 365 } @@ -52,7 +52,7 @@ func (c *cache) Set(key string, value interface{}, expire time.Duration) { } // 读取缓存 -func (c *cache) Get(key string) (interface{}, error) { +func (c *Cache) Get(key string) (interface{}, error) { if v, ok := c.store.Load(key); ok { cc := v.(*cacheData) @@ -66,12 +66,12 @@ func (c *cache) Get(key string) (interface{}, error) { } // 删除缓存 -func (c *cache) Delete(key string) { +func (c *Cache) Delete(key string) { c.store.Delete(key) } // 清空缓存 -func (c *cache) Clear() { +func (c *Cache) Clear() { c.store.Range(func(key, value interface{}) bool { c.store.Delete(key) return true