As discussed in https://reviews.llvm.org/D74398, the L1 memory cache flushing is incorrect.
For instance, if the L1 cache contains two chunks (10, 10) and (30, 10) and we call MemoryCache::Flush(25, 10), the current code does not flush anything (because it just tries to flush the previous range (10, 10) and if that is not intersecting, it will bail out).
With this patch, if the previous chunk is not overlapping, we still try the next chunk, and only if that one is not overlapping, we bail out.
This also adds some unit tests for the cache (some of the tests fail with the current code). The unit tests required some changes for testability.