title: ErrorCode<ERRCA0017>:SubStatus<ES0002> Azure Cache Service
body: <p>I am using the Azure Managed Cache service in our web application. We store some objects in the cache as well as sessions. We previously did not use the cache service to store anything other than session state. The other day I upgraded our cache from the basic offering to the standard offering and started caching some objects. Now I am seeing these errors regarding our cache:</p>
  
  <blockquote>
    <p>ErrorCode:SubStatus:There is a temporary failure. Please retry later</p>
  </blockquote>
  
  <p>The stack trace for these errors is</p>
  
  <blockquote>
    <p>Source: Microsoft.ApplicationServer.Caching.Client</p>
    
    <p>StackTrace:    at
    Microsoft.ApplicationServer.Caching.DataCache.ThrowException(ErrStatus
    errStatus, Guid trackingId, Exception responseException, Byte[][]
    payload, EndpointID destination)    at
    Microsoft.ApplicationServer.Caching.SocketClientProtocol.ExecuteApi(IVelocityRequestPacket
    request, IMonitoringListener listener)    at
    Microsoft.ApplicationServer.Caching.SocketClientProtocol.Upsert(VelocityPacketType
    type, String key, Object value, DataCacheItemVersion oldVersion,
    TimeSpan timeout, DataCacheTag[] tags, String region,
    IMonitoringListener listener)    at
    Microsoft.ApplicationServer.Caching.SocketClientProtocol.Put(String
    key, Object value, DataCacheItemVersion oldVersion, TimeSpan timeout,
    DataCacheTag[] tags, String region, IMonitoringListener listener)<br>
    at Microsoft.ApplicationServer.Caching.DataCache.InternalPut(String
    key, Object value, DataCacheItemVersion oldVersion, TimeSpan timeout,
    DataCacheTag[] tags, String region, IMonitoringListener listener)<br>
    at
    Microsoft.ApplicationServer.Caching.DataCache.&lt;>c__DisplayClass2f.b__2e()
    at
    Microsoft.ApplicationServer.Caching.MonitoringListenerFactory.EmptyListener.Microsoft.ApplicationServer.Caching.IMonitoringListener.Listen[TResult](Func<code>1
    innerDelegate)    at
    Microsoft.ApplicationServer.Caching.DataCache.Put(String key, Object
    value, TimeSpan timeout)    at
    Microsoft.Web.DistributedCache.DataCacheWrapper.Put(String key, Object
    value, TimeSpan timeout)    at
    Microsoft.Web.DistributedCache.DataCacheForwarderBase.&lt;&gt;c__DisplayClass13.&lt;Put&gt;b__12()
    at
    Microsoft.Web.DistributedCache.DataCacheForwarderBase.&lt;&gt;c__DisplayClass31</code>1.b__30()
    at
    Microsoft.Web.DistributedCache.DataCacheRetryWrapper.PerformCacheOperation(Action
    action)    at
    Microsoft.Web.DistributedCache.DataCacheForwarderBase.PerformCacheOperation[TResult](Func`1
    func)    at
    Microsoft.Web.DistributedCache.DataCacheForwarderBase.Put(String key,
    Object value, TimeSpan timeout)    at
    Microsoft.Web.DistributedCache.BlobBasedSessionStoreProvider.SetAndReleaseItemExclusive(HttpContextBase
    context, String id, SessionStateStoreData item, Object lockId, Boolean
    newItem)    at
    Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider.SetAndReleaseItemExclusive(HttpContext
    context, String id, SessionStateStoreData item, Object lockId, Boolean
    newItem)    at
    System.Web.SessionState.SessionStateModule.OnReleaseState(Object
    source, EventArgs eventArgs)    at
    System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
    Boolean&amp; completedSynchronously)</p>
  </blockquote>
  
  <p>I am wondering if these have started due to us implementing caching for our objects whereas before we were only using the service for session state. The following is my cache class.</p>
  
  <pre><code>public static class AzureCacheHelper
  {
      private static DataCacheFactory _factory;
  
      private static DataCache _cache;
  
      public static DataCacheFactory DataCacheFactory
      {
          get
          {
  
              if (_factory == null)
              {
  
                  _factory = new DataCacheFactory();
  
              }
  
              return _factory;
          }
      }
  
      public static DataCache DataCache
      {
          get
          {
              if (_cache == null)
              {
  
                  _cache = DataCacheFactory.GetDefaultCache();
  
              }
              return _cache;
          }
      }
  }
  public class AzureCache
  {        
      public void Add(string key, object value, string cacheName = "default", List&lt;string&gt; tags = null)
      {
          try
          {
              FixedInterval _retryStrategy = new FixedInterval(3, TimeSpan.FromSeconds(1));
              RetryPolicy _retryPolicy = new RetryPolicy&lt;CacheTransientErrorDetectionStrategy&gt;(_retryStrategy);
              List&lt;DataCacheTag&gt; _tags = new List&lt;DataCacheTag&gt;();
              if (tags != null)
              {
                  foreach (var tag in tags)
                      _tags.Add(new DataCacheTag(tag));
                  _retryPolicy.ExecuteAction(() =&gt;
                  {
                      AzureCacheHelper.DataCache.Add(key, value, _tags.AsEnumerable(), "all");
                  });
                  return;
              }
              _retryPolicy.ExecuteAction(() =&gt;
              {
                  AzureCacheHelper.DataCache.Put(key, value);
              });
          }
          catch (Exception e)
          { }
      }
  
      public object Get(string key, string cacheName = "default")
      {
          try
          {
              FixedInterval _retryStrategy = new FixedInterval(3, TimeSpan.FromSeconds(1));
              RetryPolicy _retryPolicy = new RetryPolicy&lt;CacheTransientErrorDetectionStrategy&gt;(_retryStrategy);
              object obj = null;
              _retryPolicy.ExecuteAction(() =&gt;
              {
                  obj = AzureCacheHelper.DataCache.Get(key);
              });
              return obj;
          }
          catch (Exception e)
          {
              ILogService logService = ObjectFactory.GetInstance&lt;ILogService&gt;();
              logService.InsertLog(LogTypeEnum.Error, "Error in cache get", e);
              logService.SaveChanges();
              return null; 
          }
      }
  
      public void Remove(string key, string cacheName = "default")
      {
          try
          {
              FixedInterval _retryStrategy = new FixedInterval(3, TimeSpan.FromSeconds(1));
              RetryPolicy _retryPolicy = new RetryPolicy&lt;CacheTransientErrorDetectionStrategy&gt;(_retryStrategy);
              _retryPolicy.ExecuteAction(() =&gt;
              {
                  AzureCacheHelper.DataCache.Remove(key);
              });
          }
          catch (Exception e)
          {  }
      }
  
      public void RemoveByPattern(string pattern, string cacheName = "default")
      {
          try
          {
              FixedInterval _retryStrategy = new FixedInterval(3, TimeSpan.FromSeconds(1));
              RetryPolicy _retryPolicy = new RetryPolicy&lt;CacheTransientErrorDetectionStrategy&gt;(_retryStrategy);
              DataCacheTag tag = new DataCacheTag(pattern);
              _retryPolicy.ExecuteAction(() =&gt;
              {
                  //IEnumerable&lt;KeyValuePair&lt;string, object&gt;&gt; items = null;
                  var items = AzureCacheHelper.DataCache.GetObjectsByTag(tag, "all");
                  foreach (var item in items)
                      AzureCacheHelper.DataCache.Remove(item.Key);
              });
          }
          catch (Exception e)
          { }
      }
  }
  </code></pre>
  
  <p>Any help on this is much appreciated. Thanks</p>