Reputation: 15179
We use Windows Server AppFabric Cache 6.1 x64. Having an instance of Microsoft.ApplicationServer.Caching.DataCache
and trying to get an object by key/region causes DataCacheException
if the region name contains characters like '!' or '.':
ErrorCode<ERRCA0018>:SubStatus<ES0001>:The request timed out.
'-', '_' are fine. However, any character is fine for item key but not for region name. MSDN is silent about any restrictions. Why? How do you escape it?
Upvotes: 2
Views: 547
Reputation: 15179
Ended up with this one:
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;
}
Upvotes: 1