Compartir a través de


Caching in the catalog system

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

  1. CatalogSchema : This applies to datasets that return schema information. These datasets will remain in the cache for the timeout defined by the cacheConfiguration.SchemaCacheTimeout property. Since the catalog schema is less likely to change once it has been defined setting the timeout to a high value can result in improved performance.

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

           

  1. Item Properties : Almost all the objects in the catalog system expose an Information property which is a dataset containing the properties for that object. For eg ProductCatalog.Information returns a dataset containing the properties of the specified product catalog. The duration the dataset returned by the Information property remains in the cache is controlled by the cacheConfiguration.ItemInformationCacheTimeout property.

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. 

 

  1. Catalog Hierarchy : The catalog system allows you to define parent child hierarchies between categories and products. This information is returned in the form of datasets. The duration for which these datasets are cached is determined by the cacheConfiguration.ItemHierarchyCacheTimeout property. The cacheConfiguration.ItemHierarchyCacheTimeout  property applies to the following methods/properties :

ProductCatalog.GetRootCategories()

ProductCatalog.GetRootProducts()

Product.AncestorCategories

Category.AncestorCategories

Product.ParentCategories

Category.ParentCategories

Product.CanonicalCategories

Category.CanonicalCategories

Category.Products

Category.ChildCategories        

           

 

  1. Catalog Relationships : The catalog system allows you to define relationships between products and categories. The duration for which the relationships datasets remain in the cache is determined by the cacheConfiguration. ItemRelationshipsCacheTimeout property and applies to the following properties

Category.RelatedCategories

Product.RelatedCategories

Category.RelatedProducts

Product.RelatedProducts

 

 

  1. Associations between different objects: The catalog system allows you to have various types of associations between different objects. For eg product catalogs associated to inventory catalogs, product catalogs to catalog sets, languages associated to product catalogs etc The duration for which these associations datasets remain in the cache is determined by the cacheConfiguration. ItemAssociationsCacheTimeout property and applies to the datasets returned by the following properties:

ProductCatalog.Languages

ProductCatalog.DependentCatalogs

VirtualCatalog.SourceCatalogs

CatalogSet.IncludedCatalogs

CatalogSet.NotIncludedCatalogs

InventoryContext.GetUnassociatedProductCatalogs

InventoryCatalog.AssociatedProductCatalogs

VirtualCatalog.VirtualCatalogRules

VirtualCatalog.PriceRules

  1. Catalog Collections : The cacheConfiguration .CatalogCollectionCacheTimeout property controls how long the following datasets remain in the cache

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.

Comments

  • Anonymous
    June 17, 2006
    Vinayak Tadas [MSFT] has released a few really great posts on some the new catalog features found in Commerce Server 2007.

  • Anonymous
    June 22, 2006
    We have finally shipped and have more time to develop tutorials and blog more about Commerce Server 2007.&amp;nbsp;...
  • Anonymous
    August 17, 2006
    Now that the Commerce Server development team has shipped their flagship product, they've started to publish some great new posts about using Commerce Server 2007. If you don't already subscribe to these blogs, you really should!
  • Anonymous
    August 29, 2006
    &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;The objects in the catalog system can now be programmed in two modes....
  • Anonymous
    October 07, 2006
    The objects in the catalog system can now be programmed in two modes. In the first mode the catalog server