3 ms·
What happens when the system of record changes the answer halfway through the transaction? By caching answers to calculations you've moved the source of truth
by hinkley 4y ago
What happens when the system of record changes the answer halfway through the transaction?
By caching answers to calculations you've moved the source of truth from the function to the cache. But the cache is also acting as a proxy for the system of record, which is a conflict of interests. That's substantially part of the problem with cache invalidation.
ETA: There's also a common category error here that I see with people who grossly misunderstand DP as 'caching'. First that they think that caching and memoization are the same thing, which they emphatically are not, and second that DP is about memoization, which means they listened for the first ten minutes and then fell asleep.
Tabulation is much more powerful than memoization, so equating DP with memoization is impoverishing it and yourself.
But importantly here, the distinction between memoization and caching is that memoization is scoped while caching is global. With memoization a single call tree gets the same answers every time, which means the mental process of Local Reasoning is maintained. If you know the call graph for this operation you know everything that interacts with it. You know if 'eviction' is even a thing. You also know that your unit tests are testing the code as it will behave under load, not some fictional happy path.
tl;dr: If your calculation is important it should show up in your data flow, not arrive out of band from a magic oracle.