The Commerce Server 2007 catalog system adds a new caching feature which caches frequently used datasets.
What is cached?
In order to prevent repeated calls to the sql server the catalog system caches the results of various methods in the catalog system. These results are cached in the form of datasets. The catalog system uses the System.Web.Caching.Cache object to cache the various datasets. Each dataset is inserted in the cache with the CacheItemPriority.Normal. The time for which a dataset remains in the cache is configurable. If not specified the default time is 5 minutes.
However in order to account for the relative frequency at which different items in the catalog system are changed we have classified the datasets in six different categories allowing you to specify different timeouts. The goal is to ensure allow for items which change less frequently to remain in the cache much longer that those that change more frequently.
The cache configuration can be defined when you create the CatalogContext object
CacheConfiguration cacheConfiguration = new CacheConfiguration();
cacheConfiguration.CacheEnabled = true;
cacheConfiguration.SchemaCacheTimeout = new TimeSpan(0, 10, 0);
cacheConfiguration.ItemAssociationsCacheTimeout = new TimeSpan(0, 10, 0);
cacheConfiguration.ItemHierarchyCacheTimeout = new TimeSpan(0, 10, 0);
cacheConfiguration.ItemInformationCacheTimeout = new TimeSpan(0, 10, 0);
cacheConfiguration.ItemRelationshipsCacheTimeout = new TimeSpan(0, 10, 0);
cacheConfiguration.CatalogCollectionCacheTimeout = new TimeSpan(0, 10, 0);
CatalogSiteAgent siteAgent = new CatalogSiteAgent();
siteAgent.SiteName = "SiteName";
CatalogContext cc = CatalogContext.Create(siteAgent, cacheConfiguration);
Caching is enabled by setting cacheConfiguration.CacheEnabled property to true.
The following are the different categories of datasets and their timeout configuration parameters
The cacheConfiguration.SchemaCacheTimeout applies to the datasets returned by the following properties/methods
CatalogContext.GetProperty()
CatalogContext.GetEntityProperties()
CatalogContext.GetProperties()
CatalogContext.GetSearchableProperties()
CatalogContext.GetPropertiesInCatalog()
ProductCatalog.PropertiesInCatalog
CatalogEnumerationProperty.EnumerationValues
CatalogContext.GetDefinitions()
CatalogDefinition.DefinitionProperties
The cacheConfiguration.ItemInformationCacheTimeout property applies to the datasets returned by the following properties/methods
CatalogSet.Information
Category.Information
InventoryCatalog.Information
InventorySku.Information
Product.Information
ProductCatalog.Information
ProductVariant.DataRow
Note that this timeout also applies to the product information stored by the QueryCatalogInfo pipeline component.
Another thing to note is that if inventory integration is enabled the inventory information also gets cached.
ProductCatalog.GetRootCategories()
ProductCatalog.GetRootProducts()
Product.AncestorCategories
Category.AncestorCategories
Product.ParentCategories
Category.ParentCategories
Product.CanonicalCategories
Category.CanonicalCategories
Category.Products
Category.ChildCategories
Category.RelatedCategories
Product.RelatedCategories
Category.RelatedProducts
Product.RelatedProducts
ProductCatalog.Languages
ProductCatalog.DependentCatalogs
VirtualCatalog.SourceCatalogs
CatalogSet.IncludedCatalogs
CatalogSet.NotIncludedCatalogs
InventoryContext.GetUnassociatedProductCatalogs
InventoryCatalog.AssociatedProductCatalogs
VirtualCatalog.VirtualCatalogRules
VirtualCatalog.PriceRules
CatalogContext.GetCatalogs()
InventoryContext.GetInventoryCatalogs()
CatalogSetsContext.GetCatalogSets
Monitoring the Catalog cache using perfmon
If you have enabled caching then you can monitor the perfomace of the cache by observing the following performance counters under Commerce : Catalog set of counters.
1. CacheTotalHits : The total number of cache hits
2. CacheTotalMissess: The total number of cache misses
3. CacheHitRate : The number of cache hits per sec
4. CacheMissRate : The number of cache misses per sec
5. CacheHitRatio : The ratio of the cache hits to the total number of cache accesses. This is equal to CacheTotalHits / (CacheTotalHits + CacheTotalMisses)
6. CacheTurnOverRate : The number of cache insert and deletes per second
Web.Config section for caching
The Caching parameters can also be set in web.config of your runtime site using the following element
<catalog>
<cache
enable="true"
schemaTimeout="10"
itemInformationCacheTimeout ="10"
itemHierarchyCacheTimeout ="10"
itemRelationshipsCacheTimeout = "10"
itemAssociationsCacheTimeout="10"
catalogCollectionCacheTimeout="10"
/>
</catalog>
Here 10 is the duration in minutes, the respective datasets should be in the cache.
Since the catalog system uses the System.Web.Caching.Cache you can tune the different aspects of the catalog cache using the ASP.NET cache settings.