From e502f581e1fd4adeb08be88a63b206b6e0bef59a Mon Sep 17 00:00:00 2001 From: xing Date: Fri, 27 Oct 2023 23:57:15 +0800 Subject: [PATCH] fix cache bug --- app/theme/wp/index.go | 3 ++- cache/map.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/theme/wp/index.go b/app/theme/wp/index.go index 5ad9db1..c081527 100644 --- a/app/theme/wp/index.go +++ b/app/theme/wp/index.go @@ -2,6 +2,7 @@ package wp import ( "database/sql" + "errors" "fmt" "github.com/fthvgb1/wp-go/app/cmd/reload" "github.com/fthvgb1/wp-go/app/pkg/cache" @@ -127,7 +128,7 @@ func (i *IndexHandle) BuildIndexData(parm *IndexParams) (err error) { return } posts, totalRows, err := i.GetIndexData() - if err != nil && err != sql.ErrNoRows { + if err != nil && !errors.Is(err, sql.ErrNoRows) { i.Stats = constraints.Error404 return } diff --git a/cache/map.go b/cache/map.go index fad20b3..12fb770 100644 --- a/cache/map.go +++ b/cache/map.go @@ -92,7 +92,7 @@ func (m *MapCache[K, V]) Flush(ctx context.Context) { func (m *MapCache[K, V]) GetCache(c context.Context, key K, timeout time.Duration, params ...any) (V, error) { data, ok := m.Get(c, key) var err error - if !ok || m.Ttl(c, key) <= 0 { + if !ok { ver := m.Ver(c, key) call := func() { m.mux.Lock() @@ -132,10 +132,10 @@ func (m *MapCache[K, V]) GetCacheBatch(c context.Context, key []K, timeout time. var res []V ver := 0 needFlush := slice.FilterAndMap(key, func(k K) (r K, ok bool) { + ver += m.Ver(c, k) if _, ok := m.Get(c, k); !ok { return k, true } - ver += m.Ver(c, k) return })