Hi Group,
I have a need to modify a sku's StockOutThreshold inventory property
when a certain basket type is saved to enable reserving stock. I am
finding however that because we have itemInformationCacheTimeout set
to 10 minutes all product and inventory properties are being cached.
If I set itemInformationCacheTimeout to 0 then the following works
fine, but of course, performance is affected.
1. Change stockout threshold of SKU123 to 10 in Catalog Manager.
2. Run IISRESET to clear any caching.
3. Run following code:
InventoryCatalog inv =
CommerceComponents.Helpers.CatalogHelper.CatalogContext.InventoryContext.GetAssociatedInventoryCatalog("CatalogName");
//
Starter site helper method.
inv.Refresh();
InventorySku sku = inv.GetSku("CatalogName", "SKU123");
sku.Refresh();
sku.StockOutThreshold = 1; // Breakpoint here shows
StockOutThreshold has the correct value of 10.
sku.Save();
4. Check Catalog Manager - threshold set to 1 as expected.
5. Run code again.
sku.Save throws an exception "The inventory sku has been updated by
another user". Debugging and checking sku.StockOutThreshold before
sku.Save shows the old value of 10 rather than the value of 1 which
was successfully updated on the previous run.
It appears that the Refresh methods do not reload the values from the
database so I only have access to the cached value. Ideally I would
want to use sku.Refresh rather than refre****ng the entire inventory
category due to performance, and the do***entation seems to state that
Refresh should reload the cache, but I don't see that happening.
I assume there must be a way to do this as the checkInventory pipeline
component appears to work correctly, bypassing the cached value.
Any help would be very welcome.
Martin.