Documentation

Ucommerce includes full API reference documentation and lots of helpful articles to help you build your e-commerce site as effortlessly as possible.

Topics Payment Providers
v7.18

How to deal with caching and indexing

Say you are running integrations either as a webservice under the website and/or as a console application or windows service running outside the website, you have to deal with the information being present on the website after the integration is done running.

The cache at this stage needs to be invalidated, as it will not be aware of the changes since it happened out of proc somewhere else. So at this point the cache on the website needs be poked. This is done best using a new web api endpoint.
In said webservice you want to use one of the techniques mentioned in this article.

Dealing with caching

The NHibernate cache that runs under the website will not be aware of your changes until you poke it as you did not write through the cache in case you ran your integration in another dedicated resource. To let the NHibernate cache aware of the change, you need to poke the cache. This can either be done per entity or using the big hammer and invalidating the entire cache depending on what you need.

Invalidating entities by ID

To invalidate entities by ID you may use the following code. This can be done for any entity type you modify through integration.

    
    //session factory holds the second level cache which needs to be cleared.
    NHibernate.ISessionFactory sessionFactory = Ucommerce.Infrastructure.ObjectFactory.Instance.Resolve<ISessionProvider>().GetSession().SessionFactory;
    
    IList<int> entityIds = new List<int>() { 1,2,3,4,5};
    
    foreach (int entityId in entityIds)
    {
        sessionFactory.Evict(typeof(Product), entityId);
    }
    
    

Invalidating the entire cache

To invalidate the entire cache you can run the following code snippet.

    
    Ucommerce.Infrastructure.ObjectFactory.Instance.Resolve<Ucommerce.EntitiesV2.ICacheProvider>().ClearCache();