Re:Caching is an Abstraction, not an Optimization
by chatmasta on Friday July 04, 2025 @07:50AM
(#44463708)
What happens when you read the cached value, after a new value has been written to the database, but before the replication has caused cache invalidation of the value?
Re:Caching is an Abstraction, not an Optimization
by necovek on Friday July 04, 2025 @01:25PM
(#44466341)
I wasn't going to say any of that ;) Yes, Postgres does have WAL log you can subscribe to, but you are creating a replicated slave really. There are many nuances to doing that right and you are downplaying how hard that is (it's not about API, it's about ACID).
More importantly, you are pushing all the complex logic to this imaginary DB replication client: your "caching system" is still nothing more than a KV store.
Re:Caching is an Abstraction, not an Optimization
by EGreg on Friday July 04, 2025 @04:07PM
(#44467481)
Well what are the “real” caching systems, if my system can be used for caching but isnt “real”? This feels like a no true scotsman argument.
Re:Caching is an Abstraction, not an Optimization
by necovek on Friday July 04, 2025 @04:41PM
(#44467718)
Caching system would be what you described as a response to my example case: your key-value store combined together with the entire mechanism to watch for DB writes (eg with triggers or the replication log) and tie them back to cached values which need to have their lifetime managed.
Mysql and Postgresql does in fact have push. It is called replication. The protocol is documented. So, much like a webhook with HTTP protocol, you can ingest changes on a table with a php long-running client and then simply update your apcu cache entries if they are still being stored, and matching that row. And all your PHP processes (managed by php-fpm or FrankenPHP or whatever) will benefit from that atomic apcu update.
There is nothing that says only another mysql server can be a mysql replication client.
Boom, solved. Even in your case. Note that the SQL database did in fact expect you to open a socket, and then it writes its log to that socket. That’s all the streaming events you need.
But now you’re gonna say “but but no you cant have a long running PHP client, we’re talking about a shared hosting environment where the host disables your ability to run a long PHP service that opens a socket”. Well, look. Most of the difficultu is that you’re intentionally trying to use the most clunky architectures just to “prove” that “cache invalidation is really hard.”
Shall we continue with Naming next? :)