SetCache stores or replaces a pricing response in the cache.
(cacheKey string, resp *api.PricingAPIResponse)
| 194 | |
| 195 | // SetCache stores or replaces a pricing response in the cache. |
| 196 | func (d *DB) SetCache(cacheKey string, resp *api.PricingAPIResponse) error { |
| 197 | data, err := json.Marshal(resp) |
| 198 | if err != nil { |
| 199 | return err |
| 200 | } |
| 201 | now := time.Now().UTC().Format(time.RFC3339) |
| 202 | _, err = d.conn.Exec( |
| 203 | "INSERT OR REPLACE INTO pricing_cache (cache_key, response_json, created_at) VALUES (?, ?, ?)", |
| 204 | cacheKey, string(data), now, |
| 205 | ) |
| 206 | return err |
| 207 | } |
| 208 | |
| 209 | // GetCacheStats returns (count, totalBytes) for pricing_cache. |
| 210 | func (d *DB) GetCacheStats() (int, int, error) { |