Fixed concurrency issue in MemoryCache

Added synchronization on critical sections. This fixes #268