Skip to content

Commit

Permalink
Gets
Browse files Browse the repository at this point in the history
  • Loading branch information
cpusoft committed Apr 12, 2024
1 parent 870ddd3 commit 9817e5c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cacheutil/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,25 @@ func (c *Cache) Get(baseKey string, key string) (value any, exist bool) {
return c.datas[baseKey].Get(key)
}

func (c *Cache) Gets(baseKey string) map[string]any {
func (c *Cache) Gets(baseKey string) (values map[string]any, exist bool) {
if baseKey == "" {
return make(map[string]any, 0)
return nil, false
}
c.mutex.RLock()
defer c.mutex.RUnlock()
if _, ok := c.datas[baseKey]; !ok {
return make(map[string]any, 0)
return nil, false
}
return c.datas[baseKey].Gets()
return c.datas[baseKey].Gets(), true
}

func (c *Cache) GetCount(baseKey string) int {
m := c.Gets(baseKey)
return len(m)
m, ok := c.Gets(baseKey)
if ok {
return len(m)
} else {
return 0
}
}

func (c *Cache) Update(baseKey string, key string, value any) {
Expand Down

0 comments on commit 9817e5c

Please sign in to comment.