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

It took me a while but I finally figured out a good caching solution and worked around the various issues. The changes are now on the 1.8 branch on GitHub for anyone that wants to help test it.

Be warned: this is beta code! It may not be suitable for production use on live websites. Also note that if you upgrade from 1.7, you won't be able to downgrade again due to changes in how user passwords and IPs are stored.

But if anyone is able to try it either on localhost or a separate test install on their server, it would be much appreciated. I will be doing some testing on my own server.

To enable caching, the following steps need to be taken:

  1. Make a folder to store the cache files and chmod it to 777. Note: for security reasons the folder must be outside your document root. In other words you must not be able to view cache files in your browser like example.com/cache/123abc456def
  2. Set the QA_CACHE_DIRECTORY constant in qa-config.php to the location you made above (see qa-config-example.php for an explanation).
  3. Go to Admin > Caching and tick "Enable caching".

Currently, question caching only applies for logged-out users. The vast majority of visits to my site were not logged in, I think that will be typical for most sites. The following things are cached:

  • Question data (answers, comments, etc) for all questions older than 7 days.
  • Related questions widget
  • Category widget

There is plenty more that can be cached, such as question lists, users page and tags page, but the above are by far the most common queries.

If you find any problems please post an answer with details. Thanks!

UPDATE: I've found a small issue with the upgrade queries when using a shared user base (the QA_MYSQL_USERS_PREFIX option). Will fix asap. Now resolved.

Q2A version: 1.8-beta
by
Have u done these two steps? as soon as you do, you will see option in admin panel.

1. Make a folder to store the cache files and chmod it to 777. Note: for security reasons the folder must be outside your document root. In other words you must not be able to view cache files in your browser like example.com/cache/123abc456def

2. Set the QA_CACHE_DIRECTORY constant in qa-config.php to the location you made above (see qa-config-example.php for an explanation).
by
Thanks
(The directory defined as QA_CACHE_DIRECTORY is not writable by the web server.)
What is the solution?
by
You need make it writable then only it will work. by default this parameter is in comment section, move it outside. If you are not able to do then contact host provider.
by
Hi q2a.info, parameter is not in comment section. its already visible only like below
    define('QA_CACHE_DIRECTORY', '/path/to/writable_cache_directory/'); ===> this is in comment section
*/
    define('QA_CACHE_DIRECTORY', '/path/to/writable_cache_directory/'); ==> this is visible.

But still getting same error, can you plz help to resolve this.

1 Answer

+2 votes
by
Hello Scott,

Is this a plugin or a part of core Q2A? I feel better to have it as a plugin so that other people can add more functionality like CDN etc later and release their version.

Thanks!
by
It's part of the core, but potentially we could make it so the caching class can be overridden if you want slightly different functionality (e.g. using Memcached instead of storing in files).

What do you mean about the CDN?
by
That will be good! others can write diff plugins.

CDN - Content Delivery Network, like Amazon CloudFront https://aws.amazon.com/cloudfront/ or maxCDN (https://www.maxcdn.com/)

Below two plugins are most popular for Wordpress which support CDN.
https://wordpress.org/plugins/w3-total-cache/ (I use this one on my site for CDN)
https://wordpress.org/plugins/wp-super-cache/
by
I think you've misunderstood what this cache does. It doesn't have anything to do with static files like CSS/JS/images. It caches the database queries, those results are used by Q2A itself and not served directly to users. So a CDN can't be used for this.
...