bug in cache writing