views:

33

answers:

1

Hello,

I have the following code:

private bool CheckForDuplicatesInCache(Message theMessage)
{
    var cacheClient = MemcachedClient.GetInstance("IntegrationCache");
    var messageHash = theMessage.GetHashCode();
    if (cacheClient.Get(messageHash.ToString()).IsNotNull())
    {
        IntegrationContext.WriteLog("Warning: This message is a duplicate. Will Not Process.");
        return false;
    }           

    cacheClient.Set(messageHash.ToString(), "nothing", new TimeSpan(2, 0, 0));

    return true;
}

The problem is, when I scale this to multiple servers...I need to have multiple memcached intances that share data for redundancy. Does anyone have any insight?

+1  A: 

There are 2 ways you could theoretically do it:

There is a product called repcached, however it only runs on linux right now. It has the ability to replicate the cache to a different server.

The other option is in code: you could write the value to BOTH caches and check for it in both chaches. If you add more than 2 servers, you could do it in a for loop.

        private bool CheckForDuplicatesInCache(Message theMessage)
    {
        var cacheClient = MemcachedClient.GetInstance("IntegrationCache");
        var cacheClient2 = MemcachedClient.GetInstance("IntegrationCache2");
        var messageHash = theMessage.GetHashCode();
        if (cacheClient.Get(messageHash.ToString()).IsNotNull())
        {
            IntegrationContext.WriteLog("Warning: This message is a duplicate. Will Not Process.");
            return false;
        }

        if (cacheClient2.Get(messageHash.ToString()).IsNotNull())
        {
            IntegrationContext.WriteLog("Warning: This message is a duplicate. Will Not Process.");
            return false;
        }

        cacheClient.Set(messageHash.ToString(), "nothing", new TimeSpan(2, 0, 0));
        cacheClient2.Set(messageHash.ToString(), "nothing", new TimeSpan(2, 0, 0));
        return true;
    }
John
I like that...seems like its kind of a hack, I shall give it a try.
Climber104