Improved error reporting when writing to cache failes.

Fixed a bug in the cache.