fix cache bug
This commit is contained in:
parent
acb064b762
commit
e502f581e1
|
@ -2,6 +2,7 @@ package wp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||||
"github.com/fthvgb1/wp-go/app/pkg/cache"
|
"github.com/fthvgb1/wp-go/app/pkg/cache"
|
||||||
|
@ -127,7 +128,7 @@ func (i *IndexHandle) BuildIndexData(parm *IndexParams) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
posts, totalRows, err := i.GetIndexData()
|
posts, totalRows, err := i.GetIndexData()
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||||
i.Stats = constraints.Error404
|
i.Stats = constraints.Error404
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
4
cache/map.go
vendored
4
cache/map.go
vendored
|
@ -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) {
|
func (m *MapCache[K, V]) GetCache(c context.Context, key K, timeout time.Duration, params ...any) (V, error) {
|
||||||
data, ok := m.Get(c, key)
|
data, ok := m.Get(c, key)
|
||||||
var err error
|
var err error
|
||||||
if !ok || m.Ttl(c, key) <= 0 {
|
if !ok {
|
||||||
ver := m.Ver(c, key)
|
ver := m.Ver(c, key)
|
||||||
call := func() {
|
call := func() {
|
||||||
m.mux.Lock()
|
m.mux.Lock()
|
||||||
|
@ -132,10 +132,10 @@ func (m *MapCache[K, V]) GetCacheBatch(c context.Context, key []K, timeout time.
|
||||||
var res []V
|
var res []V
|
||||||
ver := 0
|
ver := 0
|
||||||
needFlush := slice.FilterAndMap(key, func(k K) (r K, ok bool) {
|
needFlush := slice.FilterAndMap(key, func(k K) (r K, ok bool) {
|
||||||
|
ver += m.Ver(c, k)
|
||||||
if _, ok := m.Get(c, k); !ok {
|
if _, ok := m.Get(c, k); !ok {
|
||||||
return k, true
|
return k, true
|
||||||
}
|
}
|
||||||
ver += m.Ver(c, k)
|
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user