3

Let's say we have a wordpress site example.com

On our site, there are multiple products. Urls look like this:

example.com/products/product-1/
example.com/products/product-2/
example.com/products/product-3/
etc...

For the sake of example, let's assume following:

  • Each product page takes 10 seconds to generate. There is no way to improve hardware or software performance so generating a product page will always take 10 seconds minimum.
  • Information on product pages changes once every hour. Let's assume that each product page content changes once an hour and remains same until the next hour comes.
  • We don't want to trigger cache regeneration by an end user. In other words, if an hour passes and cache is invalid, this must be checked and updated by some process on server, by NginX, Varnish, etc... but not the end user. We don't want to have John wait 10 seconds, he's an impatient guy.
  • We don't want to do any caching on application level, no memcahed, no wp_cache plugin nothing like that. It has to be via NginX or Varnish or something like that.

Can I cache these pages and re-cahce them every hour by NginX alone?

Do I need Varnish?

How would I set this up so re-caching is done automatically for all pages?

1 Answer 1

1

If it is fine that all pages are purged at the same time, then you can do a simple cronjob which empties nginx cache directory.

For more fine-grained purging, you can use ngx_cache_purge module, and then set up a configuration that allows to purge files via specific URL calls made to the nginx server.

Then you would set up cron jobs making those calls to nginx server.

In order to use ngx_cache_purge module, you might need to compile your nginx from the source.

4
  • If I purge all cache at the same time, will Nginx recreate cache on it's own or will it wait till there is a call to a specific page and only then it will cache it? I want pages to be available in an instant to site visitors and can't rely on their requests to triger caching.
    – Jimbotron
    Aug 26, 2014 at 20:16
  • 1
    The cache for a page will be regenerated always once an user next accesses the page. It is not possible to pre-populate nginx cache. Aug 26, 2014 at 22:29
  • Tero, that's the reason why nginx may not be the right option for me then. I need the cache to be regenerated before user accesses page next time. Would Varnish do this?
    – Jimbotron
    Aug 27, 2014 at 14:22
  • Varnish doesn't do that either. One option is to visit the page right after you have purged it, which will make nginx cache the page. Aug 27, 2014 at 20:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .