updated caching to only update cache if operation is successful