mirror of
https://github.com/foomo/neosproxy.git
synced 2025-10-16 12:35:39 +00:00
Implement invalidation through DELETE /cache/all (#8)
* Implement invalidation through `DELETE /cache/all` * Fix review issues * Fix review issues
This commit is contained in:
parent
d2fc43350c
commit
34ca1ca22a
5
cache/content/getter.go
vendored
5
cache/content/getter.go
vendored
@ -27,6 +27,11 @@ func (c *Cache) Len() int {
|
||||
return counter
|
||||
}
|
||||
|
||||
// GetAll returns all cached items
|
||||
func (c *Cache) GetAll() ([]store.CacheItem, error) {
|
||||
return c.store.GetAll()
|
||||
}
|
||||
|
||||
func (c *Cache) GetAllEtags(workspace string) (etags map[string]string) {
|
||||
return c.store.GetAllEtags(workspace)
|
||||
}
|
||||
|
||||
43
proxy/api.go
43
proxy/api.go
@ -109,6 +109,49 @@ func (p *Proxy) getContent(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// invalidateCache will invalidate all cached contentserver export files
|
||||
func (p *Proxy) invalidateCacheAll(w http.ResponseWriter, r *http.Request) {
|
||||
// extract request data
|
||||
workspace := strings.TrimSpace(
|
||||
strings.ToLower(r.URL.Query().Get("workspace")),
|
||||
)
|
||||
user := r.Header.Get("X-User")
|
||||
|
||||
// validate workspace
|
||||
if workspace == "" {
|
||||
workspace = cms.WorkspaceLive
|
||||
}
|
||||
|
||||
// logger
|
||||
log := p.setupLogger(r, "invalidateCacheAll").WithFields(logrus.Fields{
|
||||
logging.FieldWorkspace: workspace,
|
||||
"user": user,
|
||||
})
|
||||
|
||||
cachedItems, err := p.contentCache.GetAll()
|
||||
if err != nil {
|
||||
log.WithError(err).Error("couldn't get all cache items")
|
||||
http.Error(
|
||||
w,
|
||||
http.StatusText(http.StatusInternalServerError),
|
||||
http.StatusInternalServerError,
|
||||
)
|
||||
}
|
||||
|
||||
if len(p.config.Neos.Dimensions) == 0 {
|
||||
log.Warn("no neos dimension configured")
|
||||
}
|
||||
|
||||
for _, ci := range cachedItems {
|
||||
p.contentCache.Invalidate(ci.ID, ci.Dimension, ci.Workspace)
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
log.
|
||||
WithField("numInvalidationRequests", len(cachedItems)).
|
||||
Debug("cache invalidation requests accepted")
|
||||
}
|
||||
|
||||
// invalidateCache will invalidate cached contentserver export file
|
||||
func (p *Proxy) invalidateCache(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
|
||||
@ -40,6 +40,7 @@ func (p *Proxy) setupRoutes() {
|
||||
// neosproxy/cache/%s?workspace=%s
|
||||
neosproxyRouter := p.router.PathPrefix(neosproxyPath).Subrouter()
|
||||
neosproxyRouter.Use(p.middlewareTokenAuth)
|
||||
neosproxyRouter.HandleFunc("/cache/all", p.invalidateCacheAll).Methods(http.MethodDelete)
|
||||
neosproxyRouter.HandleFunc("/cache/{id}", p.invalidateCache).Methods(http.MethodDelete)
|
||||
neosproxyRouter.HandleFunc("/cache/{id}", p.invalidateCache).Methods(http.MethodDelete).Queries("workspace", "{workspace}").Name("api-delete-cache")
|
||||
neosproxyRouter.HandleFunc("/status", p.streamStatus).Methods(http.MethodGet)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user