Answer_Cache
Caches answers by canonical question.
Each answer records a fingerprint of the articles it was built from and is retired when one of them changes. New or updated content retires only unanswered results, and a site-wide version retires everything when search settings change.
Namespace: WebberZone\Better_Search\Pro\AI
Since: 4.5.0
Source: includes/pro/ai/class-answer-cache.php line 23
Methods
__construct()
Register invalidation independently of whether answers are enabled.
Line: 58
public function __construct( );
touch_post() static
Mark a post as changed, retiring the answers that used it.
Edits to the post itself change its modified date; this covers changes stored elsewhere.
Since: 4.5.1
Line: 112
static public function touch_post( int $post_id ): void;
| Type | Name | Description |
|---|---|---|
int |
$post_id |
Post ID. |
Returns: void
invalidate_post_status() static
Retire unanswered results when a searchable post is published or updated, since it may now answer them.
Answers built from a post are retired by its fingerprint, so unpublishing or deleting one needs nothing here.
Since: 4.5.0
Line: 127
static public function invalidate_post_status( $new_status, $old_status, $post ): void;
| Type | Name | Description |
|---|---|---|
string |
$new_status |
New status. |
string |
$old_status |
Old status. |
\WP_Post |
$post |
Post. |
Returns: void
invalidate_updated_post() static
Retire answers that used a post when it is updated.
The modified date alone has one-second resolution, so a quick second edit could go unnoticed.
Since: 4.5.1
Line: 143
static public function invalidate_updated_post( $post_id, $post ): void;
| Type | Name | Description |
|---|---|---|
int |
$post_id |
Post ID. |
\WP_Post |
$post |
Post after the update. |
Returns: void
invalidate_object_terms() static
Retire answers that used a published searchable post whose terms changed.
Since: 4.5.0
Line: 161
static public function invalidate_object_terms( $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ): void;
| Type | Name | Description |
|---|---|---|
int |
$object_id |
Object ID. |
array |
$terms |
Terms. |
array |
$tt_ids |
New term taxonomy IDs. |
string |
$taxonomy |
Taxonomy. |
bool |
$append |
Whether terms were appended. |
array |
$old_tt_ids |
Old term taxonomy IDs. |
Returns: void
invalidate_term() static
Retire all answers when a term of a searchable post type is edited or deleted.
Since: 4.5.1
Line: 180
static public function invalidate_term( $term_id, $tt_id, $taxonomy ): void;
| Type | Name | Description |
|---|---|---|
int |
$term_id |
Term ID. |
int |
$tt_id |
Term taxonomy ID. |
string |
$taxonomy |
Taxonomy. |
Returns: void
invalidate_new_comment() static
Retire answers for a new approved comment.
Since: 4.5.0
Line: 207
static public function invalidate_new_comment( $comment_id, $approved ): void;
| Type | Name | Description |
|---|---|---|
int |
$comment_id |
Comment ID. |
int|string |
$approved |
Approval status. |
Returns: void
invalidate_edited_comment() static
Retire answers for an edited approved comment.
Since: 4.5.0
Line: 221
static public function invalidate_edited_comment( $comment_id, $data = ... ): void;
| Type | Name | Description |
|---|---|---|
int |
$comment_id |
Comment ID. |
array |
$data |
Comment data. |
Returns: void
invalidate_deleted_comment() static
Retire answers for a deleted approved comment.
Since: 4.5.0
Line: 235
static public function invalidate_deleted_comment( $comment_id, $comment = ... ): void;
| Type | Name | Description |
|---|---|---|
int |
$comment_id |
Comment ID. |
\WP_Comment|null |
$comment |
Comment. |
Returns: void
invalidate_comment_status() static
Retire answers when a comment is approved or unapproved.
Since: 4.5.0
Line: 250
static public function invalidate_comment_status( $new_status, $old_status, $comment = ... ): void;
| Type | Name | Description |
|---|---|---|
int|string |
$new_status |
New status. |
int|string |
$old_status |
Old status. |
\WP_Comment|null |
$comment |
Comment. |
Returns: void
invalidate_profile() static
Retire answers when an author changes and authors are searched.
Since: 4.5.0
Line: 261
static public function invalidate_profile( ): void;
Returns: void
invalidate_meta() static
Retire answers that used a published post when one of its indexed meta keys changes.
Since: 4.5.0
Line: 276
static public function invalidate_meta( $meta_id, $post_id, $meta_key ): void;
| Type | Name | Description |
|---|---|---|
int |
$meta_id |
Meta ID. |
int |
$post_id |
Post ID. |
string |
$meta_key |
Meta key. |
Returns: void
invalidate() static
Retire all cached answers, including externally cached transients.
Since: 4.5.0
Line: 295
static public function invalidate( ): void;
Returns: void
invalidate_unanswered() static
Retire cached unanswered results, which new or updated content may now answer.
Since: 4.5.1
Line: 304
static public function invalidate_unanswered( ): void;
Returns: void
fingerprint() static
Fingerprint of a post’s content as seen by AI answers.
Since: 4.5.1
Line: 316
static public function fingerprint( WP_Post $post ): string;
| Type | Name | Description |
|---|---|---|
\WP_Post |
$post |
Post. |
Returns: string — Fingerprint.
snapshot() static
Record the state of the articles sent to the provider, before the request is made.
Taken before the request so a post edited while the provider answers retires the answer.
Since: 4.5.1
Line: 330
static public function snapshot( array $ids ): array;
| Type | Name | Description |
|---|---|---|
int[] |
$ids |
Article IDs. |
Returns: array — Array with context (fingerprints keyed by post ID) and publish (unanswered version).
get() static
Get a cached answer.
Since: 4.5.0
Line: 357
static public function get( string $question, bool $fresh = ... ): ?array;
| Type | Name | Description |
|---|---|---|
string |
$question |
Validated question. |
bool |
$fresh |
Bypass the runtime cache, for an answer another request may have just stored. |
Returns: ?array — Cached result, or null.
lock() static
Claim the right to ask the provider a question, so concurrent visitors don’t pay for the same answer.
Since: 4.5.0
Line: 416
static public function lock( string $cache_key ): string;
| Type | Name | Description |
|---|---|---|
string |
$cache_key |
Answer cache key. |
Returns: string — Lock token, or an empty string when another request holds the lock.
unlock() static
Release a lock taken with lock().
Since: 4.5.0
Line: 443
static public function unlock( string $cache_key, string $token ): void;
| Type | Name | Description |
|---|---|---|
string |
$cache_key |
Answer cache key. |
string |
$token |
Lock token. |
Returns: void
wait() static
Wait for another request to answer the question.
Since: 4.5.0
Line: 459
static public function wait( string $question, string $cache_key ): ?array;
| Type | Name | Description |
|---|---|---|
string |
$question |
Validated question. |
string |
$cache_key |
Answer cache key. |
Returns: ?array — Cached result, or null if none arrived in time.
delete_expired_locks() static
Delete locks left behind by requests that died.
A content change alters the cache key, so such a lock is never taken over.
Since: 4.5.0
Line: 491
static public function delete_expired_locks( ): void;
Returns: void
set() static
Cache an answer.
Since: 4.5.0
Line: 519
static public function set( string $question, array $result ): void;
| Type | Name | Description |
|---|---|---|
string |
$question |
Validated question. |
array |
$result |
Result with answered, answer, sources and related, and optionally |
Returns: void
flush() static
Delete cached answers, keyword counts and the provider status.
The content version bump on the same action already stops stale answers being served; this frees the rows.
Since: 4.5.0
Line: 554
static public function flush( ): void;
Returns: void
get_key() static
Build the cache key.
Includes the settings that change the answer, the chosen provider and the locale, so a change to any of them misses the cache.
Since: 4.5.0
Line: 587
static public function get_key( string $question ): string;
| Type | Name | Description |
|---|---|---|
string |
$question |
Validated question. |
Returns: string — Transient key.
get_content_version() static
Current site content version.
Since: 4.5.0
Line: 614
static public function get_content_version( ): string;
Returns: string — Version.
get_publish_version() static
Current version for unanswered results.
Since: 4.5.1
Line: 625
static public function get_publish_version( ): string;
Returns: string — Version.