DotNetCharting CacheKey generator and .IsCached Property 

Wednesday, July 06, 2011 8:23:30 AM

DotNetCharting Maps can be painfully slow when zooming and panning around a bit. Using the built in caching can be a good booster. Unfortunately there is no way to find out wether a chart already has been cached as the .FileManger.Cached Property does not work. After some dis-assembling I came up with this Extension simulating dotNetCharting's propreitary Hash algorithm to find out whether a chart is already in the cache so you can skip your data fetching etc and save some time:

Here is the code:

public bool Cached(this Chart c)
{
    string s = c.UniqueID + HttpContext.Current.Request.Path + HttpContext.Current.Request.QueryString.ToString();
    byte[] bytes = new UnicodeEncoding().GetBytes(s);
    byte[] value = ((System.Security.Cryptography.HashAlgorithm)
System.Security.Cryptography.CryptoConfig.CreateFromName(GetHash("첀잂낄", 15))).ComputeHash(bytes);

    string cachekey = BitConverter.ToString(value);
    return HttpContext.Current.Cache(cachekey) != null;
}

public static string GetHash(string InputString, int length)
{
    char[] array = InputString.ToCharArray();
    int num = 2127053169 + length;
    int arg_47_0;
    int arg_14_0;
    if ((arg_14_0 = (arg_47_0 = 0)) < 1)
    {
        goto IL_47;
    }
IL_14:
    int num2;
    int expr_14 = num2 = arg_14_0;
    char[] arg_44_0 = array;
    int arg_44_1 = num2;
    char expr_1B = array[num2];
    byte b = (byte)((int)(expr_1B & 'ÿ') ^ num++);
    byte b2 = (byte)((int)((int)expr_1B >> 8) ^ num++);
    byte arg_3C_0 = b2;
    b2 = b;
    b = arg_3C_0;
    arg_44_0[arg_44_1] = (char)((int)b2 << 8 | b);
    arg_47_0 = expr_14 + 1;
IL_47:
    if ((arg_14_0 = arg_47_0) >= array.Length)
    {
        return string.Intern(new string(array));
    }
    goto IL_14;
}

 



Comments are closed on this post.

 
Site Map | Printable View | Design by creative & it consulting | © 2009 - 2012 Florian Morrenth