Controller having a cache memory and method of controlling the cache memory