Need To Add a Meaningless, Random Argument to End of Unread Topics URL

Started by Ranter, February 16, 2011, 02:40:28 PM

Previous topic - Next topic

Ranter

I recently installed the Varnish cache on my web server. Varnish caches both random and dynamic pages in memory for up to x seconds, currently 20 seconds in my configuration.

This is fine except on several domains using SMF forum software users are complaining that lists of unread topics are not changing after they rapidly read a message and ask for the list of unread topics again.  The list is served from the cache if it is less than 20 seconds old because the URL is the same for each user each time.

Waiting for 20 seconds is too much to ask of the users receiving free web hosting, of course. Complaining is so easy.

It has occurred to me that if each request for a new list of unread topics were to include a superfluous random argument at the end, then the page would seem to be a new request to Varnish and the request would drop through the cache to Apache/PHP/MySQL to be processed.

Here is a line of code from index.template.php where I think such a change might be made. How might I modify this to add some random, meaningless argument that SMF will happily ignore?

<li><a href="', $scripturl, '?action=unread">', $txt['unread_since_visit'], '</a></li>

Although I clearly understand the problem I could not code my way out of a shopping bag with a chainsaw, I'm afraid.

I have tested that on the SMF forum where most of the complaints are being made (running 2.0RC4) I can add a completely nonsense argument at the end in the form '&blah=foo" and SMF ignores it, which is desired.  The reason this would fix my current problem is that if each  request for unread topics had a unique URL then my cache would not match it, and it will fall through to Apache, PHP and MySQL to be processed.

Roph

<li><a href="', $scripturl, '?action=unread;', time() ,'">', $txt['unread_since_visit'], '</a></li>

This will put the time in seconds onto the URL, which should satisfy your uniqueness needs.


Advertisement: