3 ms·
> Caches are global shared state Not necessarily. I designed an object oriented simulation system which had a lot of calculated properties where the calculati
by kwhitefoot 4y ago
> Caches are global shared state
Not necessarily. I designed an object oriented simulation system which had a lot of calculated properties where the calculation was a substantial amount of work but the result would be queried many times before the input the function changed. Caching the results inside the object provided a substantial speed up (orders of magnitude) while keeping the cache completely local and hidden from the client code and keeping the program very modular.
Keeping the cache inside the objects allowed us to keep the parts of the program neatly separated and minimized the amount of knowledge that client code, and more importantly client coders, needed to have about the objects they were using.
- hinkley 4y agoWhat 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.
- bmm6o 4y agoIf we're splitting hairs, your situation sounds more like memoization, where you have saved the output of an expensive but deterministic calculation. With the correct assumptions, this can never result in incorrect behavior. Worst case is excessive memory consumption. Whereas a stale cache is something that needs to be taken into account.