[Plugin: DB Cache Reloaded] Idea: Don't cache queries that were fast enough (5 posts)

  1. Pinoy.ca
    Posted 6 years ago #

    Good job upgrading and sharing this. I can't wait to try it out in production.

    Idea: When the original query took less than x microseconds don't cache it anymore.

    The two biggest delays in retrieving past query results from the cache is (A) the filesystem and (B) the expeditious unserialize() function.

    The combined delay of these two is measurable, and either a lower limit can be benchmarked during plugin activation, or a lower limit can be hard-coded in the plugin. The byte size of the query results could be considered, of course.

    It makes no sense caching a query if running the original query is faster than retrieving a cached result.

    Hopefully this will eliminate many tiny cache files. Fewer cache files = faster cleanup. What do you think?

    See also http://wordpress.org/support/topic/252983?replies=3#post-1196721 and the one-line hack in http://wordpress.org/support/topic/234465?replies=13#post-1196851 for other ideas.


  2. Daniel Fru?y?ski (sirzooro)
    Posted 6 years ago #

    I agree with you. I will look on it to see how this can be improved.

    I also think of option to get the real-life numbers - the optimum threshold will vary from server to server.

  3. Pinoy.ca
    Posted 6 years ago #

    Thanks. If you decide to get the real-life numbers, remember to remind the blog admin to measure benchmarks during the web server and/or database server's busiest hours, that is, the time the plugin can help the most.

  4. Pinoy.ca
    Posted 6 years ago #

    Hi again,

    I tried doing this on my own, by replacing two lines in db.php from:

    $dbc_cached = serialize($dbc_cached);
    $dbc->save($dbc_cached, $dbc_queryid); }elseif($dbc_cachable) {


    if ($this->timer_stop() > 0.0001) {
    		$dbc_cached = serialize($dbc_cached);
    		$dbc->save($dbc_cached, $dbc_queryid);
    }elseif($dbc_cachable) {

    (SAVEQUERIES was defined earlier.)

    After much trial and error during my servers' busiest hours yesterday, I came to the conclusion that, at present, DB Cache doesn't help me at all. On a typical blog page of mine, during heavy traffic, running the original queries was always faster than retrieving the results from the filesystem.

    I'm writing you back right now because (a) benchmarks could show that DB Cache won't help a blog, and (b) I suggested the idea in the first place.

  5. Daniel Fru?y?ski (sirzooro)
    Posted 6 years ago #

    Thanks for sharing these results. It looks that plugin requires another cashing option - e.g. in memory.

Topic Closed

This topic has been closed to new replies.

About this Topic