How to know the generator previously used ?

Can you parse CMakeCache.txt for CMAKE_GENERATOR:INTERNAL=Ninja and similar? This is how I’ve done things like this from Python say.