Search code examples
dictionarymemcachedkeyoutputcachevoldemort

how to design/create key for key/value storage?


I want to store serialized objects (or whatever) in a key/value cache.

Now I do something like this :

public string getValue(int param1, string param2, etc )
{
    string key = param1+"_"+param2+"_"+etc;

    string tmp = getFromCache();
    if (tmp == null)
    {
       tmp = getFromAnotherPlace();
       addToCache( key, tmp);
    }
    return tmp;
}

I think it can be awkward. How can I design the key?


Solution

  • if i understood the question, i think the simplest and smartest way to make a key is to use an unidirectional hash function as MD5, SHA1 ecc...

    At least two reason for doing this:

    1. The resulting key is unique for sure!(actually both MD5 and SHA1 have been cracked (= )
    2. The resulting key has a fixed lenght!

    You have to give your object as argument of the function and you have your unique key. I don t know very much c# but i am quite sure you can find an unidirectional hash function builted-in.