2011-12-02 75 views
2

我們使用Windows Server AppFabric Cache 6.1 x64。具有Microsoft.ApplicationServer.Caching.DataCache的實例並試圖通過鍵/區域獲取對象會導致DataCacheException如果區域名稱包含字符'!'或'。':AppFabric Cache中的區域名稱限制

ErrorCode<ERRCA0018>:SubStatus<ES0001>:The request timed out. 

' - ','_'很好。但是,任何字符都適用於項目鍵,但不適用於區域名稱。 MSDN對任何限制都保持沉默。爲什麼?你如何逃避它?

回答

1

結束了這一個:

static Regex regex = new Regex(@"[^a-zA-Z_\-\d]", RegexOptions.Compiled); 

    /// <summary> 
    /// Fixes invalid characters in region names that cause 
    /// DataCacheException ErrorCode<ERRCA0018>:SubStatus<ES0001>:The request timed out. 
    /// </summary> 
    /// <param name="name">Region name to process.</param> 
    /// <returns>Escaped name where all invalid characters are replaced with their hex code.</returns> 
    protected internal static string Escape(string name) 
    { 
     if (string.IsNullOrEmpty(name)) 
      return name; 

     string result = regex.Replace(name, m => ((int)m.Value.First()).ToString("X")); 
     return result; 
    }