Browse Source

cleaner works with syncmap pointer

pull/2/head
Wmuga 3 weeks ago
parent
commit
3bbfaed475
  1. 7
      cache.go
  2. 2
      cache_test.go

7
cache.go

@ -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)
}

2
cache_test.go

@ -186,7 +186,7 @@ func TestUpdate(t *testing.T) {
val, err = c.Get(key)
if err != nil {
t.Fatal(err)
t.Error(err)
}
if val.(string) != val2 {

Loading…
Cancel
Save