MCPcopy Create free account
hub / github.com/OverloadBlitz/cloudcent-cli / GetCache

Method GetCache

internal/db/db.go:175–193  ·  view source on GitHub ↗

GetCache returns a cached pricing response for the given key if not expired.

(cacheKey string)

Source from the content-addressed store, hash-verified

173
174// GetCache returns a cached pricing response for the given key if not expired.
175func (d *DB) GetCache(cacheKey string) (*api.PricingAPIResponse, error) {
176 cutoff := time.Now().UTC().Add(-time.Duration(cacheTTLDays) * 24 * time.Hour).Format(time.RFC3339)
177 var jsonStr string
178 err := d.conn.QueryRow(
179 "SELECT response_json FROM pricing_cache WHERE cache_key = ? AND created_at > ?",
180 cacheKey, cutoff,
181 ).Scan(&jsonStr)
182 if err == sql.ErrNoRows {
183 return nil, nil
184 }
185 if err != nil {
186 return nil, err
187 }
188 var resp api.PricingAPIResponse
189 if err := json.Unmarshal([]byte(jsonStr), &resp); err != nil {
190 return nil, err
191 }
192 return &resp, nil
193}
194
195// SetCache stores or replaces a pricing response in the cache.
196func (d *DB) SetCache(cacheKey string, resp *api.PricingAPIResponse) error {

Callers 1

handleHistoryEventMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected