For example, if it takes 1 cycle to read the cache and 3 cycles to write the cache, is the hit time equal to 4 cycles? Also, does this vary based on whether the cache is an instruction cache or a data cache?
I would say, it depends.
Overall there are several strategies how a cache could be incorporated into a process. Few of these options are:
- read through: a client reads from cache, and if the cache does not have a value, then the cache itself reads the data from the store. And the cache saves the value before being returned to a customer. In this case the cost will be vary, depending if the value is already in cache.
- cache aside is another option - the client checks the cache - the cache either gives back the value or returns nothing. If the value was not found, it's the client who goes to datastore to read and also write to the cache.
There are few more strategies, and all of them will have a different cost.
Also, it is important to understand what "cache hit" and "cache miss" is. These are term unrelated to the way how cache is integrated. By definition, a cache hit happens when a client requests a key, and the key is already in the cache, regardless how that key got there. "Cache miss" is opposite - a client asks for the key, and the key is not there.