Does credits/billing info use cache?
does credits/billing info "use cache"? i'm not seeing it be reflected instantly
Now let me create a summary based on my findings:
##Answer
Yes, the credits/billing info uses cache, and that's likely why you're not seeing updates reflected instantly.
Here's what I found:
###How Caching Works
The credits/billing display uses autumn-js, a billing/pricing library. The useCustomer() hook (used in components like UserDropdown and CreditWarning) fetches customer data using SWR (Stale While Revalidate) configuration under the hood. This means:
- Data is cached - Customer billing data is cached locally on the client
- No automatic refreshes - The cache is not automatically revalidated after billing operations (like credit deductions)
- Manual refetch needed - You need to call the
refetch()function to manually refresh customer data
###Current Implementation
Looking at the code:
-
components/user-dropdown.tsxandcomponents/credit-warning.tsxboth use:const { customer, check, openBillingPortal } = useCustomer() -
The
useCustomer()hook supports an optionalswrConfigparameter with arefreshIntervaloption, but this is not currently configured in your codebase -
There's also a
refetch()function available, but it's not being called after billing operations
###The Flow
When credits are used:
- Server-side (
agent/response-agent.ts):autumn.track()is called to record usage and deduct credits - Client-side: The customer object in the dropdown doesn't update automatically - it uses the cached version
###How to Fix It
According to the Autumn documentation, you have these options:
-
Add automatic polling - Pass a
refreshIntervalin theswrConfig:const { customer, refetch } = useCustomer({ swrConfig: { refreshInterval: 5000 } // refetch every 5 seconds }) -
Call refetch manually - After tracking usage, call
refetch()to update immediately:const { customer, refetch } = useCustomer() // After some action: await refetch() -
Disable caching entirely - Set
revalidateOnFocus: trueanddedupingInterval: 0for real-time updates
Would you like me to help implement one of these solutions?
END OF POST