Lumino Astra
11/27/2025, 9:23 AMSpree::StockMovement (triggered from a background job), the DB values update correctly, but the frontend continues to display outdated stock for a few minutes. Updating stock manually through the admin panel reflects instantly, so it seems tied to how the cache invalidation is triggered.
What I’ve observed:
• on_hand updates are correct in the DB
• StockMovement callbacks fire as expected
• Variant cache is not always invalidated
• Manual cache clear fixes the issue immediately
• Occurrence rate is roughly 20–30%
This isn’t blocking anything major, but it can lead to temporary mismatches in displayed inventory, so I wanted to check if anyone else has encountered this behavior or if there are recommended approaches to ensure cache invalidation on variant stock changes.
Any insights would be appreciated. Thanks!Chris Todorov
11/27/2025, 6:13 PMupdate_column I could see how this would happen, however the way the cache invalidation works is by propagating the touch to the variant level.
You can follow the chain here
1. After stock movement is created the stock item quantity is updated in this `after_create` callback
2. In turn the stock item update will result in a touch to the associated variant in these callbacks
There are a couple of things I would check
1. The variants in question are configured to track inventory
2. What the value of the Spree::Config.inventory_cache_threshold is and if this isn't preventing certain updates from propagating to the variant
3. Ensure your cache keys in your frontend are correctly referencing the variant updated_atChris Todorov
11/27/2025, 6:16 PMLumino Astra
11/27/2025, 6:19 PMSpree::StockMovement normally. No update_column calls on stock_items, so the callback chain should be identical. I’ll compare logs side-by-side to confirm if anything differs at creation time.
• Inventory tracking: All affected variants have track_inventory enabled.
• `inventory_cache_threshold`: Currently set to the default (0), so even small changes should propagate the touch to the variant.
• Frontend cache keys: The storefront uses variant.updated_at in its keys. In the cases where stale stock appears, updated_at doesn’t always reflect the background-job stock movement.
Since it only happens ~20–30% of the time, I’m suspecting a race condition or timing issue with concurrent stock movements or cache writes. I’m adding detailed logging around the callbacks to try to get a reproducible case.
Just validating config first as you suggested. Thanks again for pointing me in the right direction! 🙏Chris Todorov
11/27/2025, 6:22 PMChris Todorov
11/27/2025, 6:24 PMLumino Astra
11/27/2025, 6:31 PMvariant.updated_at is getting touched properly from the background job, I’ll dig into the frontend caching to see if it’s occasionally missing the invalidation.
Thanks again, this definitely helps me narrow things down. 🙌Chris Todorov
11/27/2025, 6:32 PM