2013-09-05 4 views
1

Azure 데이터 캐시에서 데이터를 가져 오는 새로운 MVC 앱을 만들고 있습니다. 그러나 DataCache 객체를 인스턴스화하면 코드가 무한정 중단됩니다. 나는 오류나 타임 아웃을 얻지 못한다. 단지 새로운 객체를 생성하려고 시도한다. 결코Azure DataCache 인스턴스화

public ActionResult Index() 
{ 
    DataCache cache = new DataCache(); 
    Debugger.break; 
} 

꾸물 거리지 new DataCache() 문을지나 가져옵니다

는 순간 내 코드는 문자 그대로 이하이다. Visual Studio에서 디버거를 일시 중지하면 new DataCache() 행에서 일시 중지되는 것을 볼 수 있으므로 실행이 멈춘 곳이 분명합니다. 내가 두 번 푸른에서 그와 함께 Web.config의 경기에서 값을 확인했습니다

<dataCacheClients> 
    <dataCacheClient name="default"> 
    <!--To use the in-role flavor of Windows Azure Caching, set identifier to be the cache cluster role name --> 
    <!--To use the Windows Azure Caching Service, set identifier to be the endpoint of the cache cluster --> 
    <autoDiscover isEnabled="true" identifier="{{REMOVED}}" /> 

    <!--<localCache isEnabled="true" sync="TimeoutBased" objectCount="100000" ttlValue="300" />--> 

    <!--Use this section to specify security settings for connecting to your cache. This section is not required if your cache is hosted on a role that is a part of your cloud service. --> 
    <securityProperties mode="Message" sslEnabled="false"> 
     <messageSecurity authorizationInfo="{{REMOVED}}" /> 
    </securityProperties> 
    </dataCacheClient> 
</dataCacheClients> 

다음과 같이

내 Web.config의 내가 새 푸른 캐싱 패키지를 가져올 때 NuGet에 의해 추가 된 부분이있다 포털과 그들은 괜찮아.

누구든지이 문제의 원인을 알고 있습니까? 나는 그것이 얼마나 새로운지를 생각해 볼 때, 아주 기본적인 것을 추측하고 있습니다.

+0

어떤 유형의 캐시를 사용하고 있습니까? 공동 위치, 헌신적 인 역할 또는 공유? – viperguynaz

+0

다음과 같습니다 : - 캐시 오퍼링 - 기본 캐시 메모리 - 1GB 위치 - 서유럽; '유형'은 어떻게 결정합니까? Azure 포털에서 새 데이터 서비스 캐시 (미리보기)를 설정하고 거기에 설정했습니다. – LDJ

답변

0

당신은 공유 캐시 (캐시 서비스 미리보기)를 사용하는 - 다른 두 옵션은 캐시 '역할에 "있다 - Windows Azure Cache에서 자세한 내용을 읽어 보시기 바랍니다. config에서 모든 설정이 올바른 것으로 가정하면 캐시를 올바르게 인스턴스화하지 못합니다. How to Use Windows Azure Cache Service (Preview)을 읽으십시오.

DataCache cache = new DataCache("default"); 

나 : 당신이 중 하나를 사용할 필요가

// Cache client configured by settings in application configuration file. 
DataCacheFactory cacheFactory = new DataCacheFactory(); 
DataCache cache = cacheFactory.GetDefaultCache(); 
// Or DataCache cache = cacheFactory.GetCache("default"); 
// cache can now be used to add and retrieve items. 

를 마지막으로 캐시 개체가 비싸다 생성 - 즉 한 번 생성됩니다, 그래서 당신은 캐시에 대한 새로운 싱글 톤 클래스를 만들어야합니다 - 아니 모든 액션이 호출 된 시간. 다음은 싱글 톤 클래스의 전체 예제입니다.

public static class MyCache 
{ 
    private static DataCacheFactory _cacheFactory = null; 
    private static ObjectCache Cache 
    { 
     get 
     { 
      return MemoryCache.Default; 
     } 
    } 

    private static DataCache ACache 
    { 
     get 
     { 
      if (_cacheFactory == null) 
      { 
       try 
       { 
        _retryPolicy.ExecuteAction(() => { _cacheFactory = new DataCacheFactory(); }); 
        return _cacheFactory == null ? null : _cacheFactory.GetDefaultCache(); 
       } 
       catch (Exception ex) 
       { 
        ErrorSignal.FromCurrentContext().Raise(ex); 
        return null; 
       } 
      } 

      return _cacheFactory.GetDefaultCache(); 
     } 
    } 

    public static void FlushCache() 
    { 
     ACache.Clear(); 
    } 

    // Define your retry strategy: retry 3 times, 1 second apart. 
    private static readonly FixedInterval _retryStrategy = new FixedInterval(3, TimeSpan.FromSeconds(1)); 

    // Define your retry policy using the retry strategy and the Windows Azure storage 
    // transient fault detection strategy. 
    private static RetryPolicy _retryPolicy = new RetryPolicy<StorageTransientErrorDetectionStrategy>(_retryStrategy); 

    // Private constructor to prevent instantiation 
    // and force consumers to use the Instance property 
    static MyCache() 
    { } 

    /// <summary> 
    /// Add an item to the cache with a key and set a absolute expiration on it 
    /// </summary> 
    public static void Add(string key, object value, int minutes = 90) 
    { 
     try 
     { 
      if (RoleEnvironment.IsAvailable) 
      { 
       _retryPolicy.ExecuteAction(() => { ACache.Put(key, value, TimeSpan.FromMinutes(minutes)); }); 
      } 
      else 
      { 
       Cache.Add(key, value, new CacheItemPolicy { AbsoluteExpiration = DateTime.Now + TimeSpan.FromMinutes(minutes) }); 
      } 
     } 
     catch (Exception ex) 
     { 
      ErrorSignal.FromCurrentContext().Raise(ex); 
     } 
    } 

    /// <summary> 
    /// Add the object with the specified key to the cache if it does not exist, or replace the object if it does exist and set a absolute expiration on it 
    /// only valid for Azure caching 
    /// </summary> 
    public static void Put(string key, object value, int minutes = 90) 
    { 
     try 
     { 
      if (RoleEnvironment.IsAvailable) 
      { 
       _retryPolicy.ExecuteAction(() => { ACache.Put(key, value, TimeSpan.FromMinutes(minutes)); }); 
      } 
      else 
      { 
       Cache.Add(key, value, new CacheItemPolicy { AbsoluteExpiration = DateTime.Now + TimeSpan.FromMinutes(minutes) }); 
      } 
     } 
     catch (Exception ex) 
     { 
      ErrorSignal.FromCurrentContext().Raise(ex); 
     } 
    } 

    /// <summary> 
    /// Get a strongly typed item out of cache 
    /// </summary> 
    public static T Get<T>(string key) where T : class 
    { 
     try 
     { 
      object value = null; 

      if (RoleEnvironment.IsAvailable) 
      { 
       _retryPolicy.ExecuteAction(() => { value = ACache.Get(key); }); 
      } 
      else 
      { 
       value = Cache[key]; 
      } 

      if (value != null) return (T) value; 
      return null; 
     } 
     catch (DataCacheException ex) 
     { 
      ErrorSignal.FromCurrentContext().Raise(ex); 
      return null; 
     } 
     catch (Exception ex) 
     { 
      ErrorSignal.FromCurrentContext().Raise(ex); 
      return null; 
     } 
    } 
    /// <summary> 
    /// Microsoft's suggested method for cleaning up resources such as this in a static class 
    /// to ensure connections and other consumed resources are returned to the resource pool 
    /// as quickly as possible. 
    /// </summary> 
    public static void Uninitialize() 
    { 
     if (_cacheFactory == null) return; 
     _cacheFactory.Dispose(); 
     _cacheFactory = null; 
    } 
} 
+0

정보를 제공해 주셔서 감사합니다. 가장 유용한. 문서에 따르면 DataCache 캐시 = 새 DataCache ("기본값")는 DataCache 캐시 = 새 DataCache()와 동일합니다. 나는 또한 DataCacheFactory를 사용하여 시도했다. cacheFactory = new DataCacheFactory(); DataCache cache = cacheFactory.GetDefaultCache(); 위의 코드와 첫 문장을 지나치지 않을 것입니다. – LDJ

+0

로컬을 실행하는 경우 Azure 에뮬레이터에서 실행하고 있습니까? – viperguynaz

+0

Azure 에뮬레이터에 대해 무엇을 실행합니까? 이것은 독립 실행 형 MVC 응용 프로그램입니다. 나는 캐시를 Azure 호스트 캐시로 설정하려고 시도하고 있는데, 이는 서버로서의 in-proc 캐시가 아니라 실험 대상이다. – LDJ

0

확실히 올바른 NuGet 패키지를 추가했습니다. 당신이 사용하고있는 것은 캐시 서비스의 기본 제공 (미리보기)이며, 더 이상 사용되지 않는 공유 캐싱입니다. 식별자 필드에

, 당신은 전체 엔드 포인트의 이름을 지정하는 - [yourcachename] .cache.windows.net를?

0

여기에 내 자신의 경험을 바탕으로 내 추측이다. 캐시 서비스 미리보기를 사용하고 로컬 네트워크 (Azure 인스턴스와 반대) 및 네트워크 블록 아웃 바운드 TCP 포트 (많은 회사가 기본적으로하는 것처럼)에서 액세스하려고합니다.

당신은 어떤 시간 제한이 없었 말했지만 얼마나 기다려야 했습니까? 나는이 경우에 실패를 얻는 데 과도한 시간이 걸린다는 것을 알았지 만 오지 않았다. 그리고 예외는 캐시 클라이언트가 사용하려고하는 포트 번호를 나타냅니다. 포트 22233과 22234는 회사 네트워크에서 차단되었습니다. 문제는 IT 그룹이 해당 포트를 통해 트래픽을 통과하도록 설득했을 때 사라졌습니다.

나는 캐시 클라이언트가 사용할 수있는 모든 포트의 문서를 찾을 아직 없으며, 주제에 대한 포럼 게시물이 답을 가지고있다.

1

나는 그가 IIS Express를 사용하고 때 캐시를 칠 수 없어 맞은 편에 앉아 dev에 있어요.

그가 IIS 올바른 것으로 전환하면 작동합니다.

0

성능 카운터 초기화로 인해 DataCache 생성자가 무기한 정지됩니다.

Azure Caching NuGet 패키지를 설치할 때 프로젝트에 추가되는 ClientPerfCountersInstaller.exe을 실행하여이 문제를 해결했습니다.이 문제는 Office 2013 설치와 같은 문제를 일으킬 수있는 문제에 대한 여러 가지 보고서를 보았습니다. 관리 권한이 폴더에 cd

ClientPerfCountersInstaller in Solution Explorer

명령 프롬프트를 엽니 다. 그런 다음 다음 명령을 사용하여 설치 프로그램을 실행하십시오.

ClientPerfCountersInstaller.exe install 

그 후 내 프로젝트가 멈추지 않고 실행되었습니다.

0

나는이 스택 오버플로를 설명 할 때까지 몇 시간 동안이 문제에 대해 내 머리를 두드렸다. TL; DR : 최신 버전의 패키지가 SDK 버전 2.3에서 제대로 작동하지 않습니다. Azure Caching 2.1로 롤백하면 모든 것이 잘 동작합니다.

Exception while using Windows Azure Caching : No such host is known