1

We are currently setting up 2 Craft webservers behind a load balancer with sticky sessions.

What I am wondering: Is there any need, that

  • the file based cache needs to be somehow switched to a shared cache?
  • runtime files (@runtime) need to be shared between the 2 systems?

Especially the first question is bothering me because of how Craft can invalidate its cache.

If a shared cache is needed, what would you recommend? According to my research on the net I believe that Redis is not suitable with 2 locally installed instances (Master-Master). So either KeyDB as Redis alternative, DB Caching or file based caching via NFS would be options.

Thanks

2
  • I suppose you are already running a dedicated database server that the 2 Craft servers can talk to?
    – Johannes
    Commented Sep 24, 2021 at 13:40
  • yes, we have a dedicated DB server Commented Sep 24, 2021 at 15:17

1 Answer 1

1

Is a shared cache necessary?

In general a shared cache is not necessary because everything that is not in cache gets re-computed anyways. However, I would highly recommend a shared cache to avoid numerous issues.

An example: Imagine you have a template cache tag, the related page has been cached on all servers. Now you edit the related entry and Craft tries to clear the template cache that corresponds to that entry. The cache clear job is only run on the server that you are using the control panel at this point in time. The other servers will still have the template cache of the previous entry revision. You would have to build something to run the clear cache job on all other servers as well.

This is only one possible challenge that you could face. I am sure there are more.

To avoid a single point of failure for the cache component you could use a Redis cluster.

What to recommend?

Using Redis as cache storage type is perfectly fine. You would want to run it on a separate instance that is accessible by the multiple Craft servers. (It doesn't and shouldn't be exposed to the internet, neither directly nor via the load balancer.)

There are other possible cache storage type described in the Cache component docs.

1
  • thanks for your effort, but what I wanted to know something different: - is it not only a good idea to have a shared cache, but also a necessity? will bad things happen if I cache on both webservers separately? - I do not want one central Redis instance, I want to have something in sync (Master-Master). I want the database and the load balancer to be the single points of failure, a central REDIS would become another one... Commented Sep 24, 2021 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.