Replace ThreadLocals by variables.
Synchronize cache update in Cached(Batch)DiffFunction.