Bugfix in cache function