I have a WinForm application which is making LINQ queries to a CRM 2011 application. When I run a query I am finding that caching is enabled by default so the application is not picking up changes made in CRM unless I restart the WinForm application.
I found one post which suggests caching can be disabled by updating the configuration file to include the section below but this does not seem to have any effect - any thoughts on what I am doing wrong or any alternative approaches.
<section name="microsoft.xrm.client" type="Microsoft.Xrm.Client.Configuration.CrmSection, Microsoft.Xrm.Client"/>
<add name="Xrm" type="Xrm.XrmServiceContext, Xrm" serviceName="Xrm"/>
<add name="Xrm" type="Microsoft.Xrm.Client.Services.OrganizationService, Microsoft.Xrm.Client"/>
Refer this article
if the response answered your question, please take a minute and mark the response as an answer.
Thanks for the quick reply. That looks to do exactly what I want but the problem I have is that the Microsoft.Xrm.Client.Caching.CacheManager namespace does not seem to exist in the CRM 5 SDK - it looks to be a CRM4 SDK entry. In my project I have a reference to Microsoft.xrm.client.dll (version 5.0.9688.1154) but this only seem to have the Microsoft.xrm.client.caching.objectcachemanager namespace - am I missing a reference?
I'm doing this in CRM 5,
System.Runtime.Caching.ObjectCache cache = Microsoft.Xrm.Client.Caching.ObjectCacheManager.GetInstance();
The dll's you need to reference are located in the sdk/bin folder
- Proposed as answer by Iain_Wright Thursday, March 06, 2014 7:42 AM
You can definitely reference the ObjectCacheManager 5.0 (2011) namespace http://technet.microsoft.com/en-us/library/microsoft.xrm.client.caching.aspx . If you look up ObjectCacheManager in the sdk - it covers the implementation of the Clear and RemoveAll methods (in addition to how to add things and change the way the policies work). KBalz code below covers clear which should get you waht you want but take a look at the SDK just for reference on how to work with the cache in general - there's quite a bit of flexibility there that it sounds like you'll want to take advantage of.
Cordially, W.G.Ryan - www.williamgryan.mobi
I have tried that but it does not seem to have any effect. Stepping thru the code I can see that the Objectcache has a name or 'XRM' so it looks to be the right ccahe entity but the Clear command does not have any effect - maybe a permissions thing?
I suggest using the fully qualified namespace name if there is question if you're calling the correct class or not.
We may need to see some of your code. I did not use any special permissions to use the code I pasted earlier. You are calling the Clear command prior to your LINQ query correct?
My test code is very simple. All I do is read the entire entity and display it in a propertygrid:
Dim ObjectCache As System.Runtime.Caching.ObjectCache
ObjectCache = Microsoft.Xrm.Client.Caching.ObjectCacheManager.GetInstance
Dim Customer = (From Contact In _EServicesContext.ContactSet Where Contact.LastName.Equals("CRMTester")).FirstOrDefault
If Customer IsNot Nothing Then
PropertyGrid.SelectedObject = Customer
Whats I do is
- Run the code above and view the result
- Go to CRM and update and save a property on the entity contact where the last name is 'CRMTester'
- Run the code above again and view the results - that changes made at step 2 are not shown and tehr esults are the same as at step 1.
I know the updates to CRM are working as I have a second (non-LINQ) based query and this shows the updates correctly every time.
Many thanks for all your help with this.
This page shows some of the ways to configure caching as well as other behaviors for the service context:
Note that the uncached example there is swapping out the default CachedOrganizationService (which implements caching) with OrganizationService (which does not implement caching).
Shan McArthur www.shanmcarthur.net Check out the commercial edition of xRM portals @ www.adxstudio.com
Below are the configuration settings for removing the caches fom xrm object.
<section name="microsoft.xrm.client" type="Microsoft.Xrm.Client.Configuration.CrmSection, Microsoft.Xrm.Client" />
<add name="Crm" connectionString="Authentication Type=Integrated; Server=http://imslnkcrm03/nextstep; " />
<add name="CacheDisabled" type="Namespace.DataContextClassname, ActionPlanReportGenerator" connectionStringName="Crm" serviceName="CacheDisabled" />
<add name="CacheDisabled" type="Microsoft.Xrm.Client.Services.OrganizationService" />
XrmDataContext crm = new XrmDataContext("CacheDisabled");
- Edited by chandrabyreddy Tuesday, October 16, 2012 9:37 AM