Developer forum

Forum » Ecommerce - Standard features » Product Cache expires very often on a 9.10.10

Product Cache expires very often on a 9.10.10

Kevin Steffer
Kevin Steffer
Reply

We have just launched a site with very heavy variant combinations - we are talking 15000 combinations.

When the product is in cache it takes about 2-3 seconds to render the whole product page. But when not it takes 25-30 seconds.

But we actually exprience that the products are not cached even after 0,5 hours it's gone. And I have been looking into the cache logic and found that it uses a MemoryCache and it doesn't look like the MemoryCache entries has any lifetime on them, so how and why is the cache cleared so often?

BTW: We don't have any data integration jobs running that clears the cache (only once a week on Saturdays)


Replies

 
Nicolai Pedersen
Reply

Hi Kevin

The ProductService uses Dynamicweb.Caching.MemoryCache as you have found, and that uses Dynamicweb.Caching.CacheItemPolicy.DefaultStoragePolicy which looks like this:

new CacheItemPolicy { SlidingExpiration = new TimeSpan(0, 10, 0) };

So 10 minutes.

You might be able to override that by code the default policy is a static property that can be manipulated on application start and should last the duration of the application lifecycle - something like this (which I have not tested)

using Dynamicweb;

namespace Dynamicweb.Examples.Notifications.Standard
{
    [Dynamicweb.Extensibility.Notifications.Subscribe(Dynamicweb.Notifications.Standard.Application.AfterDynamicwebStart)]
    public class ApplicationStartObserver : Dynamicweb.Extensibility.Notifications.NotificationSubscriber
    {
        public override void OnNotify(string notification, Dynamicweb.Extensibility.Notifications.NotificationArgs args)
        {
            if (args == null)
                return;

            if (!(args is Dynamicweb.Notifications.Standard.Application.AfterDynamicwebStartArgs))
                return;

            Dynamicweb.Notifications.Standard.Application.AfterDynamicwebStartArgs item = (Dynamicweb.Notifications.Standard.Application.AfterDynamicwebStartArgs)args;

            Dynamicweb.Caching.CacheItemPolicy.DefaultStoragePolicy.SlidingExpiration.Add(new System.TimeSpan(12, 0, 0));

        }
    }
}

Are you using the classic product catalog or are you using the product catalog for viewmodels? It might be possible to change the template in a way so the 15000 combinations does not load their product record - but only the surrounding information. But I will need to see some template code to check that.

BR Nicolai

 
Kevin Steffer
Kevin Steffer
Reply

Sweeet - but is it only products that uses that policy?

Dynamicweb.Caching.CacheItemPolicy.DefaultStoragePolicy

 

 
Nicolai Pedersen
Reply

Nope. All sorts of things...

But I think this should be considered a temporary workaround. Loading the product page in 25-30 seconds should never happen, cached or not. So I think we need to look into why that is the case and find a way to avoid it.

So if we can look at the implementation of this and see how we can do something to avoid that, would be good. Maybe we should schedule a teams session? Friday or next week.

BR Nicolai

 

You must be logged in to post in the forum