Fix Api cache & add some tests.