|
|
@ -3,7 +3,6 @@ package cache |
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"fmt" |
|
|
|
"log" |
|
|
|
"sync" |
|
|
|
"time" |
|
|
|
|
|
|
@ -30,7 +29,7 @@ var ( |
|
|
|
|
|
|
|
type cache struct { |
|
|
|
ctx context.Context |
|
|
|
items sync.Map |
|
|
|
items *sync.Map |
|
|
|
expiredInterval time.Duration // Интервал, через который GС удалит запись
|
|
|
|
runGCInterval time.Duration // Интервал запуска GC
|
|
|
|
ttlcache *ttlcache.Cache |
|
|
@ -55,7 +54,7 @@ func Init(ctx context.Context, expiredInterval, runGCInterval time.Duration) { |
|
|
|
|
|
|
|
d := cache{ |
|
|
|
ctx: ctx, |
|
|
|
items: sync.Map{}, |
|
|
|
items: &sync.Map{}, |
|
|
|
runGCInterval: runGCInterval, |
|
|
|
expiredInterval: expiredInterval, |
|
|
|
ttlcache: ttlcacheNonPer, |
|
|
@ -269,7 +268,6 @@ func (c *cache) cleaner() (err error) { |
|
|
|
keys := []any{} |
|
|
|
c.items.Range(func(key, value any) bool { |
|
|
|
item, ok := value.(*cacheItem) |
|
|
|
log.Printf("%+v, %v\n", item, ok) |
|
|
|
if !ok { |
|
|
|
return false |
|
|
|
} |
|
|
@ -280,7 +278,6 @@ func (c *cache) cleaner() (err error) { |
|
|
|
|
|
|
|
return true |
|
|
|
}) |
|
|
|
log.Println(keys) |
|
|
|
for _, key := range keys { |
|
|
|
c.items.Delete(key) |
|
|
|
} |
|
|
|