Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

Improving the plugin q2a-caching (by bndr + sama55 + stevenev)

+1 vote
187 views
asked Jun 20 in Plugins by q2apro
edited Jun 21 by q2apro

I am trying the q2a-caching plugin which saves the output into the filesystem and reads it from there.

Github: https://github.com/stevenev/q2a-caching

It seems to work great, as it reduces my mysql process from 86 % to 26 % load. Awesome.

However, it seesms that the plugin is removing the entire file cache on an event happening.

1. Incoming event triggers clear_cache(): https://github.com/stevenev/q2a-caching/blob/master/qa-caching-event.php#L16

2. clear_cache() deletes entire cache: https://github.com/stevenev/q2a-caching/blob/master/qa-caching-main.php#L134

I am pretty sure that this is not necessary. Instead, we should get the postid from the event and only remove this specific cached site/file. But not the others.

Any ideas how to do the caching better?

Q2A version: 1.8.0

1 Answer

0 votes
answered Jun 21 by q2apro
edited Jun 21 by q2apro

Alright, I have changed the original plugin so that it caches only questions.

Each question gets updated when there is a change to it, such as answer added, edit, upvote etc.

It's beta, so please test it and report back: https://github.com/q2apro/q2apro-caching

You need to create a folder /qa-cache in your root. – The names of the cache files are the questionids!

The other versions of the plugin work well, however, they empty the entire file cache on incoming events. This plugin here only deletes the specific question page if it gets changed. So basically it should be more performant. Testers needed :)

Thanks for any feedback.

commented Jul 24 by q2apro
Probably the theme uses two different CSS files? In the recent plugin version I commented-out the part for this, enable it again: https://github.com/q2apro/q2apro-caching/blob/master/qa-caching-main.php#L430

return QA_CACHING_DIR . '/' . $md5 . ( $this->mobile? '_mobile': '_desktop' );

This should fix it.
commented Jul 24 by vivian
Another problem with pagination. If our question has many answers then the next page button won't work on this cached page.
...