0
votes

I need to implement like/dislike functionality (for anonymous users so there is no need to sign up). Problem is that content is served by Varnish and I need to display actual number of likes.

I'm wondering how it's done on website like stackoverflow. Assuming pages are cached in Varnish (for anonymous users only), so every time user votes on answer/question, page needs to be purged from cache. Am I right? Current number of votes needs to be visible for other users.

What is good approach in this situation? Should I send PURGE to Varnish every time user hits "like" button?

1

1 Answers

1
votes

A common way of implementing this is to do the like button and display client side in Javascript instead. This avoids the issue slightly.

Assuming that pressing Like leads to a POST request hitting a single Varnish server, you can make the object be invalidated/replaced in different ways. Using purge and a VCL restart is most likely the better way to do this.

Of course there is a slight race here, where other clients will be served the old page while this is ongoing.