Correctly memoise io module

Thanks to Charlie Paucard for the report.