Does credits/billing info use cache?
does credits/billing info "use cache"? i'm not seeing it be reflected instantly
I'll help you investigate the credits/billing info caching behavior. Let me search the codebase for related code.
Let me search more specifically for cache-related patterns and how customer data is fetched:
Now let me search for where customer data is fetched and how it handles billing info:
Let me check the user-dropdown component and look for the useCustomer hook:
Now let me check what autumn-js/react is and how it fetches customer data:
Let me check the autumn.config.ts to understand how it's configured:
Let me search for where the customer billing info is actually fetched from the backend:
Let me check the AutumnProvider to see how it's configured:
Now let me search for where billing usage is tracked and updated:
Let me check the response-agent.ts file to see how it tracks billing:
Now let me check how the autumn library works - let me look at the actual implementation in lib/autumn/index.ts:
Now let me search for how the customer data is refreshed on the client side, and if there's any specific caching behavior:
Let me check the library's documentation by searching the web for autumn-js caching behavior:
Perfect! I found the key information. According to the Autumn documentation, the useCustomer hook has a refetch() method available, and it also accepts an optional swrConfig parameter that allows you to customize caching and revalidation behavior using SWR (Stale While Revalidate) configuration. Let me verify if this is being used in the code:
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
Claude Haiku 4.5