Fix bug in `total_energy()` where all cache would be returned instead
of selecting relevant rows from cache. #216