PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.10
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.10
4.4.10 4.4.9.1 4.4.9 4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 All 142 releases
← All changes | inc/user-item/class-lp-user-item-quiz.php +25 -1 4.4.2 → 4.4.10 View file →
@@ -207,9 +207,9 @@
207 207 }
208 208
209 209 $lp_quiz_cache = LP_Quiz_Cache::instance();
210 210
211 - $key_cache = sprintf( '%d/user/%d/course/%d', $this->get_item_id(), $this->get_user_id(), $this->get_course_id() );
211 + $key_cache = $this->get_results_cache_key();
212 212 $result = $lp_quiz_cache->get_cache( $key_cache );
213 213
214 214 if ( false === $result || $force ) {
215 215 // $result = $this->_get_results();
@@ -229,8 +229,31 @@
229 229 return $prop ? $result[ $prop ] : new LP_Quiz_Results( $result );
230 230 }
231 231
232 232 /**
233 + * Key of the cache filled by @see LP_User_Item_Quiz::get_results.
234 + *
235 + * @return string
236 + */
237 + public function get_results_cache_key(): string {
238 + return sprintf( '%d/user/%d/course/%d', $this->get_item_id(), $this->get_user_id(), $this->get_course_id() );
239 + }
240 +
241 + /**
242 + * Drop the cached result of this quiz for this user.
243 + *
244 + * get_results() caches what it calculates, and that cache outlives the request wherever a
245 + * persistent object cache is installed. Anything that rewrites the stored result must clear
246 + * it, or the next read serves the result from before the write - a quiz submitted after the
247 + * in-progress result was cached comes back with every question still unanswered.
248 + *
249 + * @return void
250 + */
251 + public function clear_results_cache() {
252 + LP_Quiz_Cache::instance()->clear( $this->get_results_cache_key() );
253 + }
254 +
255 + /**
233 256 * Get user quiz graduation text for displaying purpose. [Passed, Failed, null]
234 257 *
235 258 * @since 4.0.0
236 259 *
@@ -765,8 +788,9 @@
765 788
766 789 $result_answer = $this->calculate_quiz_result( $answered_check );
767 790
768 791 LP_User_Items_Result_DB::instance()->update( $this->get_user_item_id(), json_encode( $result_answer ) );
792 + $this->clear_results_cache();
769 793 $this->add_checked_question( $question_id );
770 794
771 795 $checked['answered'] = $answered;
772 796 $checked['mark'] = $result_answer['questions'][ $question_id ]['mark'];