I'll try to be simple, so what i need is, perform a MySQL query (selecting records from a table) let's say ill produce the query with cron jobs or whatever every 5 minutes, and save this query or results to a file or a global variable if it's possible, and then serving it to all clients (i.e. using the same query to all users, without having to reconnect to that database.) Now i know some of you will tell me to use cache, but i searched for it, and if the table changes there will be new cache, and my table is constantly changing, now i don't care if the table has changed, i just want to serve the same query to all clients. Is that possible? your recommendations please. Thanks.
The cache expires automatically when the table is modified (inserts, updates, delete's, etc). And my table is constantly changing, so is it possible to save a cache even if the table has been modified? or should i look for a different solution?
If the result set isn't too big, you could cache it into a generated script like so:
file_put_contents(
'mycache.php',
'<?php return ' . var_export($results, true) . ' ?>'
);
Then to use it:
$results = include 'mycache.php';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With