Fixed bug in cache handling