【问题标题】:Clearing cache in XRM 2011 with ObjectCacheManager使用 ObjectCacheManager 清除 XRM 2011 中的缓存
【发布时间】:2012-02-08 20:45:44
【问题描述】:

在过去,我有这个 http://arens.ws/wordpress/?p=54

public static void ClearCache(string entityName)
{
  const string format = "adxdependency:crm:entity:{0}";
  var dependency = string.Format(format, entityName).ToLower();

  var cache = Microsoft.Xrm.Client.Caching.CacheManager.GetBaseCache();
  cache.Remove(dependency);
}

2011 年的情况有所不同。有任何想法吗?

【问题讨论】:

    标签: dynamics-crm xrm


    【解决方案1】:

    它只改变了一点点:

    ObjectCache cache = Microsoft.Xrm.Client.Caching.ObjectCacheManager
        .GetInstance("Xrm");
    string cachekey = String.Format("xrm:dependency:entity:{0}:id={1:D}", 
        entity.LogicalName, entity.Id);
    cache.Remove(cachekey);
    

    我没有找到这方面的文档,通过枚举缓存找到了键命名方案。可能使用这不是最佳实践,它可能会在下一个版本中再次更改?应该有更好的方法来做到这一点......

    [更新] 有一个better way

    试试这个:

    var serviceContext = (Get an OrganizationServiceContext);
    
    var serviceContainer = serviceContext as 
                               OrganizationServiceContainer;
    var cachedOrgService = serviceContainer.Service as 
                               CachedOrganizationService;
    var orgServiceCache = cachedOrgService.Cache as 
                               IOrganizationServiceCache;
    var entity = (Get the entity that was updated);
    
    orgServiceCache.Remove(entity.LogicalName, entity.Id);
    

    像魅力一样工作......

    【讨论】:

      猜你喜欢
      • 2012-01-08
      • 2019-10-14
      • 1970-01-01
      • 2021-10-27
      • 2015-10-27
      • 2018-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多