Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
2.6k views
in Q2A Core by
edited by

I've noticed that Q2A sends several headers to prevent caching on all pages:

	Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache

However, for old questions the chance of them changing is quite low. So wouldn't it be beneficial to remove those headers if a question is more than a week old, or set them to cache for at least a few hours?

Also, would it be at all feasible to cache pages server-side, or parts of pages? If a user is logged in there will be certain parts that can't be cached, but a good chunk of the HTML should be cacheable, right?

2 Answers

0 votes
by
For now, Q2A doesn't modify the standard HTTP headers that PHP adds. You can certainly change this using PHP's header() function in a custom theme (use print_r($this->content) to see everything passed to the theme layer - you'll find info direct from the database in the 'raw' subarray elements).

As for server-side caching, it's a long-term goal, but there is so much to be done in the meantime! The next version will have a simple integrated caching mechanism (used for caching scaled down avatars) so in the meantime you could plug into that.
by
Are you saying those headers are not added by Q2A? Where would they be coming from then? The regular pages on my site don't return them.
by
PHP is adding those headers - try making a simple PHP file and they should also appear when the file is requested. It's also possible some of them are a side effect of the Gzip compression that Q2A activates.
by
I found the culprit - the sessions. On every Q2A page load, a session is started whether the user is logged in or not. I don't know if that's necessary when the user is not logged in... I guess if they log in then get returned to the previous page you don't want it cached in the browser.
+3 votes
by

Hi!

If you need to cache pages for unregistered users, check out my plugin:  https://github.com/bndr/q2a-caching

It's a work in progress, Caching for registered users is in the todo list.

by
Error! When enabled cache does not work entry through facebook.
by
Hi! I think I fixed the issue.

I removed caching from register/login pages. And stopped caching for users with cookies values that contain fbs_

It should work now. Get the new version from the repository and try it
by
Hi.
So we get an error:
Warning: preg_match() [function.preg-match]: No ending delimiter '#' found in /var/www/szh/data/www/szh.kz/qa-plugin/q2a-caching/qa-caching-main.php on line 122
by
Sorry about that. Fixed.
...