Added an option to flush periodically, rather than after every write.