I'm interested to know what the opinions are of those on this list with 
regards to caching objects during database write operations. I've encountered 
different views and I'm not really sure what the best approach is.

Take a typical caching scenario: Data/objects are locally stored upon loading 
from a database to improve performance for subsequent requests. But when 
those objects change, what's the best method for refreshing the cache? There 
are two possible approaches (maybe more?):

1) The old cache entry is overwritten with the new.
2) The old cache entry is expired, thus forcing a database hit (and 
subsequent cache load) on the next request.

The first approach would tend to yield better performance. However there's no 
guarantee the data will ever be read. The cache could end up with a large 
amount of data that's never referenced. The second approach would probably 
allow for a smaller cache by ensuring that data is only cached on reads.

In the end, this probably boils down to application requirements. RAM and 
disk storage is so cheap these days that the first method is probably fine 
for most purposes. However I'm sure there are situations where resources are 
limited and the second is more effective. What does everyone think?

-- 
Milo Hyson
CyberLife Labs, LLC

Reply via email to