Cache tests and bugfix