• Support
  • Add cache to ajax admin calls to reduce server load?

Hi there - We received the following note from our hosting company asking if anything could be done about missing cache for the ajax-admin calls. Here's the note:

_We're seeing a lot of expensive/un-cached admin-ajax requests being made on every page of the site. These requests are always missing cache, which means that they have to be processed by PHP and are therefore causing high CPU load on the server when a large number of such requests is made in a short amount of time.

The admin-ajax requests belong to the buttonizer-multifunctional-button-premium plugin and looks like this:

GET https://www.example.com/wp-admin/admin-ajax.php?action=buttonizer&qpu=b2bad81de1154ee0a2a112a5f35776b0&preview=0&data[page]=3000&data[blog]=1&data[is_404]=false&data[is_front_page]=false&data[title]=Retail Industry&data[url]=https://www.example.com/retail-industry/

Responses to such requests are also setting the following cache headers which mean that requests are never cached:

cache-control: no-cache, must-revalidate, max-age=0_

Is there any chance we can add a cache to reduce the high CPU load on the server?

Hi StevePo ,

First of all, welcome to the Buttonizer Community!

Buttonizer does not change any cache-header at this moment (expecting WordPress, the webserver or the client-browser handles this). From our tests this happens in the most cases.

However, it is possible that a plugin changes the cache-control header in their advantages. What you could try is forcing the cache-control for the admin-ajax.php?action=buttonizer URL via your .htaccess file.

Example code:

<IfModule mod_headers.c>
    <If "%{THE_REQUEST} =~ m#\s\/wp-admin\/admin-ajax\.php\?action=buttonizer(.*)#">
        Header set Cache-Control: "max-age=1800"
    </If>
</IfModule>

This way you are able to customize the Cache-Controls for Buttonizer only. The responses of the code above will be cached client-side for 30 minutes (30 * 60 seconds).

Let me know if this helps 🙂