AppFabric Cache中的区域名称限制

时间:2011-12-02 09:23:55

标签: .net caching appfabric

我们使用Windows Server AppFabric Cache 6.1 x64。如果区域名称包含“!”之类的字符,则拥有Microsoft.ApplicationServer.Caching.DataCache实例并尝试按键/区域获取对象会导致DataCacheException或'。':

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

' - ','_'很好。但是,任何字符都适用于项目键,但不适用于区域名称。 MSDN对任何限制都保持沉默。为什么?你怎么逃避它?

1 个答案:

答案 0 :(得分: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;
    }