MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / GetWithCache

Method GetWithCache

pkg/api/client.go:160–203  ·  view source on GitHub ↗

GetWithCache makes a GET request to the Proxmox API with caching.

(path string, result *map[string]interface{}, ttl time.Duration)

Source from the content-addressed store, hash-verified

158
159// GetWithCache makes a GET request to the Proxmox API with caching.
160func (c *Client) GetWithCache(path string, result *map[string]interface{}, ttl time.Duration) error {
161 // Generate cache key based on API path
162 cacheKey := fmt.Sprintf("proxmox_api_%s_%s", c.baseURL, path)
163 cacheKey = strings.ReplaceAll(cacheKey, "/", "_")
164
165 // Try to get from cache first
166 var cachedData map[string]interface{}
167
168 found, err := c.cache.Get(cacheKey, &cachedData)
169 if err != nil {
170 c.logger.Debug("Cache error for %s: %v", path, err)
171 } else if found {
172 c.logger.Debug("Cache hit for: %s", path)
173
174 if result != nil {
175 // Copy the cached data to the result
176 *result = make(map[string]interface{}, len(cachedData))
177 for k, v := range cachedData {
178 (*result)[k] = v
179 }
180
181 return nil
182 }
183 }
184
185 // Cache miss or error, make the API call
186 c.logger.Debug("Cache miss for: %s", path)
187
188 err = c.Get(path, result)
189 if err != nil {
190 return err
191 }
192
193 // Cache the result
194 if result != nil && *result != nil {
195 if err := c.cache.Set(cacheKey, *result, ttl); err != nil {
196 c.logger.Debug("Failed to cache API result for %s: %v", path, err)
197 } else {
198 c.logger.Debug("Cached API result for %s with TTL %v", path, ttl)
199 }
200 }
201
202 return nil
203}
204
205// GetWithRetry makes a GET request with retry logic and timeout.
206func (c *Client) GetWithRetry(path string, result *map[string]interface{}, maxRetries int) error {

Callers 15

GetStorageContentMethod · 0.95
GetNodeStatusMethod · 0.95
GetNodeConfigMethod · 0.95
GetNodeStoragesMethod · 0.95
GetLxcInterfacesMethod · 0.95
GetNodeDisksMethod · 0.95
GetNodeDiskSmartMethod · 0.95
GetVmStatusMethod · 0.95
GetDetailedVmInfoMethod · 0.95
GetNodeUpdatesMethod · 0.95
getClusterBasicStatusMethod · 0.95

Calls 4

GetMethod · 0.95
GetMethod · 0.65
DebugMethod · 0.65
SetMethod · 0.65