Which is more expensive (in $): database memory or processing power?
My suggestion would be to store the cache in DB-tables, not in memory. If the entries  are referenced a lot, they will be in memory (in disk buffers). The advantage of this approach is that the diffs will be competing for a place in core with the other DB tables, which is always smarter than pre-allocating (and managing) XXX bytes of memory.
An addtional advantage is that maintaining {hitcount,date of access, ...} for the cache entries is relatively easy, and its management can all be done in SQL.
And remember: disk space is for free. It is very easy to have an XXX GB cache on disk, and effectively using only XXX MB of it. The hard hitters will be in memory while the long tail will sit on disk. And it is always possible to grow or shrink the cache.
Cost estimate for the uncached version:

I/O + buffer memory cost for 2 files
CPU + memory cost for the diff operation
buffer memory for the result.

Cost estimate for the cached version:

I/O + to fetch the diff
CPU + memory for the query
buffer memory for the result

If you compare the two:

the uncached version has a larger I/O cost (given the diff is smaller than the sum of the two files)
The uncached version always has a larger memory footprint
The query cost could be smaller than diff-execution cost. Or it could be larger...
This is a fairly abstract question, I hope it is within bounds.
I'm about 5 months into my coding career in web development.  I've found that there's often a tension between CPU and storage resources.  Put simply, you can use less of one and more of the other, or vice versa (then throw in the speed consideration).  I'm now getting to the point of deploying my first app for production, so this balance is now a matter of real dollars and cents.  The thing is this: I really don't have any idea what kind of balance I should be looking for.
Here's some salient examples that might illuminate the balance to be struck in different case scenarios.
Background
I am working on an app that does alot of diffs between text.  Users will call on pages that contain diffs displayed in html.  A lot.
First Case
Should I run a diff each time a page is displayed, or should I run the diff once, store it, and call it each time a page is displayed?
Second Case
I have coded up an algorithm that summarises diffs.  It's about 110 lines of code, and it uses 4 or 5 loops and subloops.  Again, should I run this once and store the results, so that they can be called on later, or should I just run the algorithm each time a page is displayed?
Would also love to hear your views on the best tools to use to quantify the balance.