make preview cache work with encryption and improve error handling