rtCamp / nginx-helper

Nginx Helper for WordPress caching, permalinks & efficient file handling in multisite
https://wordpress.org/plugins/nginx-helper/
224 stars 117 forks source link

What are advantages of redis cache over nginx cache? #313

Open DeeKey opened 6 months ago

DeeKey commented 6 months ago

I am using nginx cache with module ngx_cache_purge. Does redis cache (with nginx with module srcache) has advantages over the nginx cache? What are they?

gagan0123 commented 6 months ago

@DeeKey

There are several advantages of using Redis cache over the default NGINX cache:

  1. Redis, being in memory cache, can serve requests faster (though we can mount NGINX cache in TMPFS which stays in RAM)
  2. Redis offers various eviction policies, letting you control how and when data is removed from the cache. This is more flexible compared to NGINX's caching mechanism.
  3. If you are building a distributed system, a single Redis instance can serve multiple NGINX instances running on different servers (similar thing can be achieved by having an NFS mount of the NGINX cache directory, but not that efficient)
  4. In Redis cache, you can purge pattern-based URLs all at once in a single request, e.g. https://example.com/category/* but the same is not possible in NGINX cache (as I remember) and you have to either send multiple requests to clear all cached pages matching that pattern individually, or clear the entire cache.

I hope this answers your question

DeeKey commented 6 months ago

In my setup NGINX cache is in TMPFS (/dev/shm). But the biggest problem with this setup is slow delete of cache during post editing. Thus I hope that pattern based purging might help me to speed up the purging process!