Rename lib_store and redis_store imports. Cache get remove redundant nil check.
This commit is contained in:
parent
472dc0c358
commit
f718a6b798
3 changed files with 11 additions and 12 deletions
|
|
@ -9,9 +9,8 @@ import (
|
||||||
"github.com/mikestefanello/pagoda/pkg/context"
|
"github.com/mikestefanello/pagoda/pkg/context"
|
||||||
"github.com/mikestefanello/pagoda/pkg/services"
|
"github.com/mikestefanello/pagoda/pkg/services"
|
||||||
|
|
||||||
lib_store "github.com/eko/gocache/lib/v4/store"
|
libstore "github.com/eko/gocache/lib/v4/store"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/redis/go-redis/v9"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// CachedPageGroup stores the cache group for cached pages
|
// CachedPageGroup stores the cache group for cached pages
|
||||||
|
|
@ -58,7 +57,7 @@ func ServeCachedPage(ch *services.CacheClient) echo.MiddlewareFunc {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, &lib_store.NotFound{}) || err == redis.Nil:
|
case errors.Is(err, &libstore.NotFound{}):
|
||||||
c.Logger().Info("no cached page found")
|
c.Logger().Info("no cached page found")
|
||||||
case context.IsCanceledError(err):
|
case context.IsCanceledError(err):
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ import (
|
||||||
|
|
||||||
"github.com/eko/gocache/lib/v4/cache"
|
"github.com/eko/gocache/lib/v4/cache"
|
||||||
"github.com/eko/gocache/lib/v4/marshaler"
|
"github.com/eko/gocache/lib/v4/marshaler"
|
||||||
lib_store "github.com/eko/gocache/lib/v4/store"
|
libstore "github.com/eko/gocache/lib/v4/store"
|
||||||
redis_store "github.com/eko/gocache/store/redis/v4"
|
redisstore "github.com/eko/gocache/store/redis/v4"
|
||||||
"github.com/mikestefanello/pagoda/config"
|
"github.com/mikestefanello/pagoda/config"
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
)
|
)
|
||||||
|
|
@ -77,7 +77,7 @@ func NewCacheClient(cfg *config.Config) (*CacheClient, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cacheStore := redis_store.NewRedis(c.Client)
|
cacheStore := redisstore.NewRedis(c.Client)
|
||||||
c.cache = cache.New[any](cacheStore)
|
c.cache = cache.New[any](cacheStore)
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
@ -152,9 +152,9 @@ func (c *cacheSet) Save(ctx context.Context) error {
|
||||||
return errors.New("no cache key specified")
|
return errors.New("no cache key specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := []lib_store.Option{
|
opts := []libstore.Option{
|
||||||
lib_store.WithExpiration(c.expiration),
|
libstore.WithExpiration(c.expiration),
|
||||||
lib_store.WithTags(c.tags),
|
libstore.WithTags(c.tags),
|
||||||
}
|
}
|
||||||
|
|
||||||
return marshaler.
|
return marshaler.
|
||||||
|
|
@ -214,7 +214,7 @@ func (c *cacheFlush) Tags(tags ...string) *cacheFlush {
|
||||||
// Execute flushes the data from the cache
|
// Execute flushes the data from the cache
|
||||||
func (c *cacheFlush) Execute(ctx context.Context) error {
|
func (c *cacheFlush) Execute(ctx context.Context) error {
|
||||||
if len(c.tags) > 0 {
|
if len(c.tags) > 0 {
|
||||||
if err := c.client.cache.Invalidate(ctx, lib_store.WithInvalidateTags(c.tags)); err != nil {
|
if err := c.client.cache.Invalidate(ctx, libstore.WithInvalidateTags(c.tags)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
lib_store "github.com/eko/gocache/lib/v4/store"
|
libstore "github.com/eko/gocache/lib/v4/store"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
@ -64,7 +64,7 @@ func TestCacheClient(t *testing.T) {
|
||||||
Key(key).
|
Key(key).
|
||||||
Type(new(cacheTest)).
|
Type(new(cacheTest)).
|
||||||
Fetch(context.Background())
|
Fetch(context.Background())
|
||||||
assert.True(t, errors.Is(err, &lib_store.NotFound{}))
|
assert.True(t, errors.Is(err, &libstore.NotFound{}))
|
||||||
}
|
}
|
||||||
assertFlushed()
|
assertFlushed()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue