forked from designwall/dw-question-answer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.php
22 lines (18 loc) · 796 Bytes
/
cache.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
/**
* Use transient api to imporve speed of DW Question Answer
*/
add_action( 'dwqa_add_answer', 'dwqa_update_transient_when_add_answer', 10, 2 );
function dwqa_update_transient_when_add_answer( $answer_id, $question_id ) {
// Update cache for latest answer of this question
$answer = get_post( $answer_id );
set_transient( 'dwqa_latest_answer_for_' . $question_id, $answer, 60*60*6 );
delete_transient( 'dwqa_answer_count_for_' . $question_id );
}
add_action( 'dwqa_delete_answer', 'dwqa_update_transient_when_remove_answer', 10, 2 );
function dwqa_update_transient_when_remove_answer( $answer_id, $question_id ) {
// Remove Cached Latest Answer
delete_transient( 'dwqa_latest_answer_for_' . $question_id );
delete_transient( 'dwqa_answer_count_for_' . $question_id );
}
?>