ErrorCode<ERRCA0017>:SubStatus<ES0002> Azure Cache Service

314 Views Asked by At

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:

ErrorCode:SubStatus:There is a temporary failure. Please retry later

The stack trace for these errors is

Source: Microsoft.ApplicationServer.Caching.Client

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)
at Microsoft.ApplicationServer.Caching.DataCache.InternalPut(String key, Object value, DataCacheItemVersion oldVersion, TimeSpan timeout, DataCacheTag[] tags, String region, IMonitoringListener listener)
at Microsoft.ApplicationServer.Caching.DataCache.<>c__DisplayClass2f.b__2e() at Microsoft.ApplicationServer.Caching.MonitoringListenerFactory.EmptyListener.Microsoft.ApplicationServer.Caching.IMonitoringListener.Listen[TResult](Func1 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.<>c__DisplayClass13.<Put>b__12() at Microsoft.Web.DistributedCache.DataCacheForwarderBase.<>c__DisplayClass311.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& completedSynchronously)

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.

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<string> tags = null)
    {
        try
        {
            FixedInterval _retryStrategy = new FixedInterval(3, TimeSpan.FromSeconds(1));
            RetryPolicy _retryPolicy = new RetryPolicy<CacheTransientErrorDetectionStrategy>(_retryStrategy);
            List<DataCacheTag> _tags = new List<DataCacheTag>();
            if (tags != null)
            {
                foreach (var tag in tags)
                    _tags.Add(new DataCacheTag(tag));
                _retryPolicy.ExecuteAction(() =>
                {
                    AzureCacheHelper.DataCache.Add(key, value, _tags.AsEnumerable(), "all");
                });
                return;
            }
            _retryPolicy.ExecuteAction(() =>
            {
                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<CacheTransientErrorDetectionStrategy>(_retryStrategy);
            object obj = null;
            _retryPolicy.ExecuteAction(() =>
            {
                obj = AzureCacheHelper.DataCache.Get(key);
            });
            return obj;
        }
        catch (Exception e)
        {
            ILogService logService = ObjectFactory.GetInstance<ILogService>();
            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<CacheTransientErrorDetectionStrategy>(_retryStrategy);
            _retryPolicy.ExecuteAction(() =>
            {
                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<CacheTransientErrorDetectionStrategy>(_retryStrategy);
            DataCacheTag tag = new DataCacheTag(pattern);
            _retryPolicy.ExecuteAction(() =>
            {
                //IEnumerable<KeyValuePair<string, object>> items = null;
                var items = AzureCacheHelper.DataCache.GetObjectsByTag(tag, "all");
                foreach (var item in items)
                    AzureCacheHelper.DataCache.Remove(item.Key);
            });
        }
        catch (Exception e)
        { }
    }
}

Any help on this is much appreciated. Thanks

0

There are 0 best solutions below