title: Object Caching using C# in CRM Online
body: <p>I am using Object Caching in C# to store an EntityCollection in Cache.</p>
  
  <p>Following is the code for caching : </p>
  
  <pre><code>ObjectCache cache = MemoryCache.Default;
  const string keyName = "BrandPartners";
  EntityCollection result;
  
  if (!cache.Contains(keyName))
  {
      result = GetCustomerData(service, firstName, lastName, gender);
      var cacheItemPolicy = new CacheItemPolicy()
      {
          AbsoluteExpiration = DateTime.Now.AddMinutes(5)
      };
  
      tracingService.Trace("Writing into the cache");
      cache.Add(keyName, result, cacheItemPolicy);
  }
  else
  {
      result = (EntityCollection)cache.Get(keyName);
      tracingService.Trace("Data already found in the cache");
  }
  </code></pre>
  
  <p>So, when I am first creating a record in an entity in an instance in CRM online, I am getting the trace  : "Writing into the cache."</p>
  
  <p>But, when I am again creating a record in the same entity, I am again getting the same trace ("Writing into the cache"). But, if I am using caching, I should not get this trace because the keyName of "BrandPartners" already exist in the cache.</p>
  
  <p>So, what am I doing wrong?</p>