ClearNodeCache selectively invalidates cache entries for a specific node. This is more efficient than clearing the entire cache when only one node's data needs to be refreshed.
(nodeName string)
| 302 | // This is more efficient than clearing the entire cache when only one node's |
| 303 | // data needs to be refreshed. |
| 304 | func (c *Client) ClearNodeCache(nodeName string) { |
| 305 | nodePaths := []string{ |
| 306 | fmt.Sprintf("/nodes/%s/status", nodeName), |
| 307 | fmt.Sprintf("/nodes/%s/version", nodeName), |
| 308 | fmt.Sprintf("/nodes/%s/config", nodeName), |
| 309 | fmt.Sprintf("/nodes/%s/disks/list", nodeName), |
| 310 | fmt.Sprintf("/nodes/%s/apt/update", nodeName), |
| 311 | } |
| 312 | |
| 313 | for _, path := range nodePaths { |
| 314 | cacheKey := fmt.Sprintf("proxmox_api_%s_%s", c.baseURL, path) |
| 315 | cacheKey = strings.ReplaceAll(cacheKey, "/", "_") |
| 316 | |
| 317 | _ = c.cache.Delete(cacheKey) |
| 318 | } |
| 319 | |
| 320 | c.logger.Debug("Cache entries cleared for node %s", nodeName) |
| 321 | } |
| 322 | |
| 323 | // GetCache returns the cache instance used by this client. |
| 324 | // This is useful for sharing cache instances across multiple clients in group mode. |
no test coverage detected