ErrorCode <errca0017>:SubStatus <es0002> Azure缓存服务</es0002> </errca0017>

时间:2014-12-11 05:35:26

标签: c# azure azure-caching

我在我们的Web应用程序中使用Azure托管缓存服务。我们将一些对象存储在缓存中以及会话中。我们以前没有使用缓存服务来存储会话状态以外的任何内容。前几天我将缓存从基本产品升级到标准产品,并开始缓存一些对象。现在我看到有关缓存的这些错误:

  

ErrorCode:SubStatus:暂时失败。请稍后重试

这些错误的堆栈跟踪是

  

来源:Microsoft.ApplicationServer.Caching.Client

     

StackTrace:at   Microsoft.ApplicationServer.Caching.DataCache.ThrowException(ErrStatus   errStatus,Guid trackingId,Exception responseException,Byte [] []   有效载荷,EndpointID目的地)at   Microsoft.ApplicationServer.Caching.SocketClientProtocol.ExecuteApi(IVelocityRequestPacket   请求,IMonitoringListener监听器)   Microsoft.ApplicationServer.Caching.SocketClientProtocol.Upsert(VelocityPacketType   type,String key,Object value,DataCacheItemVersion oldVersion,   TimeSpan超时,DataCacheTag []标签,字符串区域,   IMonitoringListener监听器)   Microsoft.ApplicationServer.Caching.SocketClientProtocol.Put(字符串   key,Object value,DataCacheItemVersion oldVersion,TimeSpan超时,   DataCacheTag []标签,字符串区域,IMonitoringListener监听器)
  在Microsoft.ApplicationServer.Caching.DataCache.InternalPut(String   key,Object value,DataCacheItemVersion oldVersion,TimeSpan超时,   DataCacheTag []标签,字符串区域,IMonitoringListener监听器)
  在   Microsoft.ApplicationServer.Caching.DataCache&LT;&GT; c__DisplayClass2f.b__2e()   在   Microsoft.ApplicationServer.Caching.MonitoringListenerFactory.EmptyListener.Microsoft.ApplicationServer.Caching.IMonitoringListener.Listen [TResult](Func键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.<>c__DisplayClass13.<Put>b__12() at Microsoft.Web.DistributedCache.DataCacheForwarderBase.<>c__DisplayClass31 1.b__30()   在   Microsoft.Web.DistributedCache.DataCacheRetryWrapper.PerformCacheOperation(动作   行动)   Microsoft.Web.DistributedCache.DataCacheForwarderBase.PerformCacheOperation [TResult](Func`1   func)at   Microsoft.Web.DistributedCache.DataCacheForwarderBase.Put(String key,   对象值,TimeSpan超时)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(对象   source,EventArgs eventArgs)at   System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()   在System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,   布尔和放大器; completedSynchronously)

我想知道这些是否已经开始由于我们为我们的对象实现缓存而在我们仅使用服务进行会话状态之前。以下是我的缓存类。

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)
        { }
    }
}

非常感谢任何帮助。感谢

0 个答案:

没有答案
相关问题