Fix: UI not refreshing after ZFS pool operations due to caching

This commit is contained in:
2025-12-16 19:58:52 +07:00
parent e1a66dc7df
commit 0c70777181
4 changed files with 21 additions and 5 deletions

View File

@@ -1,6 +1,8 @@
package httpapp
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"log"
@@ -76,6 +78,12 @@ func (a *App) handleCreatePool(w http.ResponseWriter, r *http.Request) {
return
}
// Invalidate cache for GET /api/v1/pools
keyToInvalidate := "GET:/api/v1/pools"
hash := sha256.Sum256([]byte(keyToInvalidate))
cacheKey := hex.EncodeToString(hash[:])
a.cache.Invalidate(cacheKey)
pool, err := a.zfs.GetPool(req.Name)
if err != nil {
writeJSON(w, http.StatusCreated, map[string]string{"message": "pool created", "name": req.Name})
@@ -114,6 +122,12 @@ func (a *App) handleDeletePool(w http.ResponseWriter, r *http.Request) {
return
}
// Invalidate cache for GET /api/v1/pools
keyToInvalidate := "GET:/api/v1/pools"
hash := sha256.Sum256([]byte(keyToInvalidate))
cacheKey := hex.EncodeToString(hash[:])
a.cache.Invalidate(cacheKey)
writeJSON(w, http.StatusOK, map[string]string{"message": "pool destroyed", "name": name})
}