How to cache a very dynamic website in PHP?

139 Views Asked by At

I have a section on my site called Views where one user can see who has viewed their profile. Can this be cached considering the fact that it kind of needs to be real-time so that if the users checks this page or refresh every 30 seconds, they can see the new visitor?

Another section I have is Messages where users message each-other. This also needs to be real-time. Can this be cached?

The other section I'd like to cache is new users section where user can see newly registered users.

Have you guys had experience with something similar and how did you go on about solving it?

The purpose of this is to reduce the number of calls to the Database. I want to look at this option and fine tune everything before increasing my database's limitations.

Thank you.

1

There are 1 best solutions below

2
On

Normally caching means that you save a site that you don't have to calculate them every time and save performance.

A good solution for that is Varnish and ESI. You can exclude parts of your code and replace them with ESI tags. Varnish fetch that URL and put them together and deliver the whole site. you have some possibilities that Varnish fetch them lazy so when a user go to the page he get the old version and in background Varnish load a new one for the next request.

https://www.varnish-cache.org/trac/wiki/ESIfeatures

https://www.varnish-cache.org/docs/4.0/users-guide/esi.html

Some Frameworks have plugins for Varnish and have implemented that ESI functions and replace automatically part of your page.