Added locking mechanisms to the cache