fix cache bug

This commit is contained in:
xing 2023-10-27 23:57:15 +08:00
parent acb064b762
commit e502f581e1
2 changed files with 4 additions and 3 deletions

View File

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

4
cache/map.go vendored
View File

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