_prime_post_caches()
Додає до об’єктного кешу зазначені записи (пости). Пости, які вже є у кеші, пропускаються. Також створює пов’язаний кеш термінів та метаданих.
Ця функція вважається внутрішньою для використання самим ядром . Не рекомендується використовувати цю функцію у своєму коді.
1 раз – 0.012805 сек
(гальмо) | 50000 разів – 0.78 сек
(дуже швидко)
(гальмо) | 50000 разів – 0.78 сек
(дуже швидко)
Хуків немає.
Повертає
null
. Нічого.
Використання
_prime_post_caches($ids, $update_term_cache, $update_meta_cache);
-
$ids
(масив) (обов’язковий) - Масив ID записів, які потрібно перевірити і якщо їх ще немає у кеші, додати до кешу.
-
$update_term_cache
(true/false) -
Чи потрібно оновлювати пов’язаний кеш термінів (категорій).
Типово: true -
$update_meta_cache
(true/false) -
Чи потрібно оновлювати пов’язаний кеш метаданих (довільних полів).
Типово: true
Приклади
#1 Додамо записи в кеш при обробці коментарів
Приклад із ядра, з функції get_comments() .
/ / Prime comment post caches. if ( $this->query_vars['update_comment_post_cache'] ) { $comment_post_ids = array(); foreach ( $_comments as $_comment ) { $comment_post_ids[] = $_comment->comment_post_ID; } _prime_post_caches( $comment_post_ids, false, false ); }
#2 Додамо записи в кеш при отриманні постів
Приклад із ядра, з функції get_posts() .
$ids = $wpdb->get_col( $this->request ); if ($ids) { $this->posts = $ids; $this->set_found_posts( $q, $limits ); _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); } else { $this->posts = array(); }
нотатки
- Дивіться: update_post_caches()
- Global. wpdb. $wpdb WordPress database abstraction object.
список змін
З версії 3.4.0 | Введено. |
Код _prime_post_caches() prime post caches WP 6.0.2
function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache = true ) { Global $wpdb; $non_cached_ids = _get_non_cached_ids($ids, 'posts'); if ( ! empty( $non_cached_ids ) ) { $fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", implode( ',', $non_cached_ids ) ) ); update_post_caches($fresh_posts, 'any', $update_term_cache, $update_meta_cache); } }