A quick Google search didn't give back any info on how EPiServer Commerce uses caching for its catalog and entries. My question is is there a tech-note or similar I can look at to learn more about EPiServer Commerce's caching functionality? What I'm wondering about:
Caching for each subsytem is configured in the confiuration file that goes with it. For catalog, you will want to refer to ecf.catalog.config in the configs folder of your site.
<Cache enabled="true" collectionTimeout="0:1:0" entryTimeout="0:1:0" nodeTimeout="0:1:0" schemaTimeout="0:2:0"/>
The collection timeout responds to an entry array, and entry responds to a single entry. What is actually cached is the CatalogEntryDto. Since the Entry object is created from the dto we chose to cache to the dto.
The cache is invalidated when it hits the cache timeout specified above for the request type. It can also be invalidated if the whole catalog cache is cleared by calling CatalogCache.Clear(). Another way to invalidate for a particualr entry is to remove the key using CatalogCache.Remove(key). When calling CatalogContext.SaveCatalogEntry, it will automatically remove the entry from the different cache keys by calling
CatalogCache.RemoveByPattern("^" + CatalogCache.CreateCacheKey("catalogentry"));
CatalogCache.RemoveByPattern("^" + CatalogCache.CreateCacheKey("catalogentries"));
CatalogCache.RemoveByPattern("^" + CatalogCache.CreateCacheKey("catalogitems"));
Some customers will cache the entry objects themselves rather than the DTO. Some customers that were using memcached before using episerver commerce have also used memcahced to store entry objects and will have the memcahced object update every so often.
If you want to hook into the catalog event system to create a depency for you own cache you can look at the following link.
How about when running multiple servers? Will it only invalidate the local cache of that server? Thanks for your answers Mark, helps alot :).
Only for the local cache of the server. There are improvements to the caching layer on the roadmap for commerce.
I find the topic interesting but i still have questions after reading your post Mark. At the productdetail page. The first time i hit any product it takes relativly long time to load. But for subsequent requests its fast. To me it seems like its the complete catalog that is cached, and not what i request specificly. I am kindda worried cause we have below 100 items in the catalog for now ...
CatalogContext.Current.GetCatalogEntry(code, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
to fetch the entry. The entry has multiple variants.
What do you mean when you say the first time it takes a long time. After the app pool starts each product detail page takes a long time or just one. IS this after compiling the solution.
I investigated the problem a little deeper. I put on a MVCMiniProfiler. Our problem is in no way related to commerce and the catalog.
The problem is related to loading the display template control dynamicly. First time i load the control it takes relativly long time (and the app has been compiled and initialized at this time). But its off topic, so will investigate this further and perhaps take it up with EPiServer support.