From 276ecdc6f2a4e9f6b0221d1cc68f178cfff9f186 Mon Sep 17 00:00:00 2001 From: Evan J Date: Mon, 7 Sep 2020 13:44:21 -0700 Subject: [PATCH] Fix(cache): When deleting item, don't error out on cache miss of the item. --- internal/s/cache/content.go | 7 ++++++- internal/s/cache/contenttype.go | 7 ++++++- internal/s/cache/space.go | 9 ++++++++- internal/s/hook/hook.go | 5 ++++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/internal/s/cache/content.go b/internal/s/cache/content.go index 153b55d..6151aa9 100644 --- a/internal/s/cache/content.go +++ b/internal/s/cache/content.go @@ -100,7 +100,12 @@ func (c *Cache) ContentDelete(ctx context.Context, u user.User, space space.Spac } } - return c.mc.Delete(key) + // Don't care if cache miss. + if err := c.mc.Delete(key); err != nil && !errors.Is(err, memcache.ErrCacheMiss) { + return err + } + + return nil } // TODO: ContentPerContentType diff --git a/internal/s/cache/contenttype.go b/internal/s/cache/contenttype.go index 66e5126..90749ca 100644 --- a/internal/s/cache/contenttype.go +++ b/internal/s/cache/contenttype.go @@ -133,7 +133,12 @@ func (c *Cache) ContentTypeDelete(ctx context.Context, u user.User, space space. } } - return c.mc.Delete(key) + // Don't care if cache miss. + if err := c.mc.Delete(key); err != nil && !errors.Is(err, memcache.ErrCacheMiss) { + return err + } + + return nil } // TODO: ContentTypeUpdate diff --git a/internal/s/cache/space.go b/internal/s/cache/space.go index 20bbb5c..ee1edc2 100644 --- a/internal/s/cache/space.go +++ b/internal/s/cache/space.go @@ -2,11 +2,13 @@ package cache import ( "context" + "errors" "fmt" "git.sr.ht/~evanj/cms/internal/m/space" "git.sr.ht/~evanj/cms/internal/m/user" "git.sr.ht/~evanj/cms/internal/s/db" + "github.com/bradfitz/gomemcache/memcache" ) func (c *Cache) space(breakCache bool, key string, getter func() (space.Space, error)) (space.Space, error) { @@ -68,7 +70,12 @@ func (c *Cache) SpaceDelete(ctx context.Context, u user.User, s space.Space) err return deleteErr } - return c.mc.Delete(key) + // Don't care if cache miss. + if err := c.mc.Delete(key); err != nil && !errors.Is(err, memcache.ErrCacheMiss) { + return err + } + + return nil } // TODO: SpacesPerUser diff --git a/internal/s/hook/hook.go b/internal/s/hook/hook.go index de34e8c..d805f93 100644 --- a/internal/s/hook/hook.go +++ b/internal/s/hook/hook.go @@ -71,7 +71,10 @@ func (h *Hook) do(ctx context.Context, content content.Content, hook hook.Hook, res := strings.TrimSpace(string(bytes)) if resp.StatusCode != http.StatusOK { - return fmt.Errorf("%s", res) + return fmt.Errorf("did not receive a status ok from remote server: status code: %d: response body: \"%s\"", + resp.StatusCode, + res, + ) } return nil -- 2.45.2