Refreshing Cache from Mojave API

on Friday, December 19, 2008

My last post was regarding how to refresh CS07 cache concerning the web services. It is important to note however that when you are dealing with Mojave code, such as working on the Default Site that ships with CTP4 (or upcoming CTP5), that the code does not use these web services. These web services are used by integration applications (e.g. Biztalk) or the management application MMCs (e.g. Customers and Orders Manager, Catalog Manager, etc.).

One example would be when you a user adds a credit card to his profile. A new credit card entry is created which includes all the information e.g. credit card number, expiry date, etc. However, it does not include the DateCreated i.e. the time stamp at which the user created the credit card entry on the site. This attribute is filled in on the Commerce Server/Sql Server side. Therefore your local cached copy of the newly created credit card will not have DateCreated attribute in the cache. Why is this a problem? Well, if you want to sort the credit cards by DateCreated attribute, this is a problem. You will not be able to do a meaningful sort until and unless the CS07 cache refreshes. An iisreset, for example, will clear the cache for you. Note that resetting the cache from the management applications or changing the settings in the Commerce Server web services' web.config will have no effect. Remember, you are making Mojave calls which are going straight to CS07 (Microsoft.CommerceServer.* libraries). The web services are simply not in the play here.

So, how do you refresh Commerce Server 2007 cache from Mojave API? There are two ways:

1. Directly Using CommerceUpdate

CommerceUpdate updateCache = new CommerceUpdate();
updateCache.SearchCriteria.Model.Name = "ProfileCache";

CommerceResponse response = OperationService.ProcessRequest(GetCurrentRequestContext(), updateCache.ToRequest());

2. When a CommerceQuery is done. If the search criteria contains the last modified date, it will be evaluated against the retrieved user profile and if different, the CS2007 cache will be refreshed.

CommerceQuery query = new CommerceQuery();
query.SearchCriteria.Model.DateModified = DateTime.UtcNow;
query.SearchCriteria.Model.Email = email;

0 comments: