Hi there,
Can someone advice me how to best cache products? I need to find a way to quickly retrieve specific products without a lot of overhead. Here's my scenario:
I need to display a list of products, where for each product the "preferred variant" must be shown. Preferred in this case means it contains a specific color. I can't show the original product as I need variant data such as price, options and custom fields.
Here's my current logic:
foreach (Product product in Products)
{
foreach (VariantCombination vc in product.VariantCombinations)
{
if (vc.IsMatch())
{
productCollection.Add(vc.Product);
}
}
}
return productCollection;
IsMatch is a (fake) Extension method that determines if the product is "preferred".
This works fine, but suffers from the N+1 issue; I fire one select statement for the list of products, and then fire a separate query for each product to get the associated variants as they are lazy loaded. Performance tests show that this is slowing things down considerably.
What I am thinking about is loading all products on application startup and loop through the variants to lazy load them, and then cache the results. I can do in-line querying against this cached collection. Alternatively, I could build up the cache for each product I loop over, so I only take the performance hit once.
Is this a good idea? I can potentially have up to 100 products, each with around 20 to 40 variants, leading to 4000 cached products. Is that a bad idea? Any experience with this amount of cached data?
Or are there better solutions available?
Kind regards,
Imar
Developer forum
E-mail notifications
Caching best practices
Posted on 09/11/2010 16:37:59
Replies
Posted on 12/11/2010 13:15:30
Hi Imar,
I can't think of any better way of doing it than what you've described...at the moment!
But with Dynamicweb 7.2 you will have the advantage of the Lucene index, which will out-perform any caching you can do yourself.
I believe the wait will be worth while, but then again: I'm not aware of your deadlines. But it's probably a yesterday kinda' thing? :-)
I can't think of any better way of doing it than what you've described...at the moment!
But with Dynamicweb 7.2 you will have the advantage of the Lucene index, which will out-perform any caching you can do yourself.
I believe the wait will be worth while, but then again: I'm not aware of your deadlines. But it's probably a yesterday kinda' thing? :-)
Posted on 12/11/2010 15:57:26
It's not really a "yesterday" thing, but I don't think we can wait until DW 7.2 arrives and then upgrade. It needs to be running withing the next two weeks or so.
Is caching 4000 products feasible? Or is there too much memory overhead involved? I have no idea how large a Product is in memory....
Imar
Is caching 4000 products feasible? Or is there too much memory overhead involved? I have no idea how large a Product is in memory....
Imar
Nicolai Høeg Pedersen
Posted on 15/11/2010 10:25:15
4000 products will do fine in memory - my guess would be between 500-800 MB in total for the solution. But be sure to have a seperate app pool for this solution - and make sure you do not have 10 memeroy consuming sites on the same server with only 3 GB available for IIS...
Running IIS 7 in 64 bit will make it easier to handle the memory - it has way higher limits on memory.
Running IIS 7 in 64 bit will make it easier to handle the memory - it has way higher limits on memory.
You must be logged in to post in the forum