~evanj/cms

276ecdc6f2a4e9f6b0221d1cc68f178cfff9f186 — Evan J 2 months ago 820a001
Fix(cache): When deleting item, don't error out on cache miss of the
item.
M internal/s/cache/content.go => internal/s/cache/content.go +6 -1
@@ 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

M internal/s/cache/contenttype.go => internal/s/cache/contenttype.go +6 -1
@@ 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

M internal/s/cache/space.go => internal/s/cache/space.go +8 -1
@@ 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

M internal/s/hook/hook.go => internal/s/hook/hook.go +4 -1
@@ 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