tags:

views:

17

answers:

2

Not really sure how to do this but i can cache the dictionary like this:

Cache.Insert("CacheName", Dictionary)

need some direction. the dictionary is two string values taken from a database. The user will input a string and i need to compare it against the values in the cached dictionary.

A: 

You can get the dictionary out of the cache by writing

var dict = (Dictionary<X, Y>) cache["CacheName"];
SLaks
A: 

In general you need to access the object from the cache, cast it, and the use the ContainsKey property. Here is an example:

First add the dictionary to the Cache:

IDictionary<string, string> testDict = new Dictionary<string, string>();
testDict.Add("Test", "test");
Cache.Insert("dict", testDict);

Then, when you need to do so, access the cached object and use it ContainsKey property to determine whether it contains the searched key or not.

 var dict = Cache["dict"] as IDictionary<string, string>;

 if (dict != null)
 {
     string testValue = "test";
     if(dict.ContainsKey(testValue))
     {
        /* some logic here */ 
     }     
 }

You can access the value the following way:

if (dict != null)
 {
     string testValue = "test";
     if(dict.ContainsKey(testValue))
     {
        /* some logic here */ 
        string value = dict[testValue];
     }     
 }
Genady Sergeev
That seems to work pretty swell, now i just need to get the key of the value which was found and set it equal to a string
wil
I've updated my post accordingly :)
Genady Sergeev
Thanks, much appreciated!
wil