I have w3 total cache installed, but i have a custom plugin that i use to pull information from a large database. I use this to generate sidebar information. For example, i have custom fields for posts that allow me to associate a movie/game/person etc with a post. When the post loads i take this Id and perform a DB lookup to get information on this ID and then build the HTML. Rather than perform this SQL lookup every single time, would it be quicker if i saved the HTML to a file and refreshed it every now and then?

The reason i ask is because i ran P3 Plugin Profiler and my custom plugin is responsible for 60% of the page load time, so i badly need to make it more efficient.

Her eis what im doing. Posts have custom meta fields. A single post will have an ID of eg. 3. The widget will then perform a WP query to find other posts with the same ID. Other widgets will take the Id and perform an SQL query to get information for the movie from another database external to wordpress. so say a review for terminator, this will have the meta movie id for the movie from an external database that has all of the movie information. I want to find other posts related to the same movie based on the movieId and also get the movie information. This means it will be non existent for some posts and different for others. A cache will need to be done for each page.

My main question is will a file cache be faster than dynamically loading it each time?

    Global $IDFromPostMetaField1;

    if($IDFromPostMetaField1 != "")
        //sometimes this will be an SQL query and not a WP query
        $myquery = new WP_Query( "post_type=post&meta_key=abc....");
        $relatedposts = $myquery->posts;

        if(count($relatedposts) > 0) 
            //display other posts that are related to this movie.
    //do some other form of similar lookup
  • what is the built in cache system? – user1889580 Oct 13 '15 at 7:23
  • I have written a basic skeleton for a widget with build in cache. Use that as a template to rewrite your custom widget – Pieter Goosen Oct 13 '15 at 7:30
  • will this work for a dynamic widget? it will be different and sometimes non existent depending on the page – user1889580 Oct 13 '15 at 7:34
  • File an edit and post your code – Pieter Goosen Oct 13 '15 at 7:50
  • 1
    The answer to your question depends on the sever the site is running on and the hard disk type being used and caching used by the OS, and cache hit rate in your code. It is just impossible to answer. – Mark Kaplun Oct 13 '15 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.