add batch writes in cache.

In this PR, batch writes is added to the in memory cache as mentioned in #182
Ok. Lets do that then. I feel bad for dragging this PR this far. But I think by making this change, we will simplify the code a lot and bring down the corner cases.