Caching help


On my front page (index.php) I do 2 queries that can pull quite a bit of data.

I am concerned that it is too resource intensive. What I would like my system to do is to update the page itself say every 5 mins and display that data - rather than rerunning the two queries every time someone lands on the page.

I believe hat this is called “caching” but I am unsure exactly what it is and how to do it.

If someone could name my problem more accurately and suggest an approach with some tools - I should be able to figure out the particulars.

I am right now a little unsure what and how to do this - or even if I should.

yes, query caching is the appropriate terminology

it very much depends on which software you want to use or have access to

my former web site¹ was database driven, with ColdFusion as the front-end language, which allowed query caching right in the individual query syntax –

    <CFPARAM NAME="request.whichentryid" DEFAULT="10">
    <CFQUERY NAME="sqlatequery" 
             BLOCKFACTOR="100" >
    select name 
         , url  
         , date_format(added,"%e %M %Y") as dateadded
      from links  
     where privacy = 0
       and entryid =   #request.whichentryid# 
        by added desc
    <CFCATCH TYPE="Database">
      <CFSET request.errormsg = 
             ,"Database error D937F04C; please notify administrator. ")>
    <CFIF Len(request.errormsg)>
      <!--- this query is allowed to return 0 rows --->

your mileage with php may vary

¹ it’s now static html only

Thanks ok so it is called query caching.

I am using vanilla php and reverse proxy nginx in front of Apache… Any other pointers?

Deepest thx!

Query caching is something that is done by MySQL itself, you don’t need to set that up. What you might need to set up is how big those caches are, but if it’s only two queries I’m pretty sure you’ll be fine running the defaults.

Have you done some actual tests that show the queries are slow, or is it just a feeling you have? I would always make sure first that it’s actually a problem before trying to solve it. Premature optimisation is the root of all evil.

Haha lol - just a “feeling”.

I will hold the premature optimization. You are right it quickly gets crazy when you start looking into all the things that “can” be done. I can probably just start with nginx, single MariaDB and one server!!

Hmm… cool perspective!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.