How do I cache a very dynamic website in PHP?

I have a section on my site called Views

where one user can see who viewed their profile. Can this be cached given the fact that it has to be in real time so that if users check this page or refresh every 30 seconds they can see a new visitor?

Another section I have is Messages

where users communicate to each other. It should also be in real time. Could this be cached?

Another section that I would like to cache is new users

where the user can see new registered users.

Have you guys had an experience with something similar and how did you keep 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 limits in the database.

Thank.

+3


source to share


1 answer


Usually, caching means you save a site that you don't need to compute every time, and save performance.

A good solution for this is varnish and ESI. You can exclude parts of your code and replace them with ESI tags. Varnish extracts this url and puts it together and delivers the entire site. you have some capabilities that Lac brings them lazy, so when the user navigates to the page, he gets the old version and in the background Lak loads 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 ESI functionality implemented and automatically replaced with part of your page.

+1


source







All Articles