fix cache clearing and suport for streaming. Add tests