Recent

Answer_CacheclassPro only

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 articles retire only unanswered results, and a version of its own retires everything when the settings or knowledge base terms change.

Namespace: WebberZone\Knowledge_Base\Pro\AI
Since: 3.2.0
Source: includes/pro/ai/class-answer-cache.php line 23

Methods

__construct()

Register invalidation independently of whether Ask the Docs is enabled.

Line: 65

public function __construct(  );

touch_post() static

Mark an article as changed, retiring the answers that used it.

Edits to the article itself change its modified date; this covers changes stored elsewhere.

Since: 3.2.0
Line: 96

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 an article is published or updated, since it may now answer them.

Answers built from an article are retired by its fingerprint, so unpublishing or deleting one needs nothing here.

Since: 3.2.0
Line: 111

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 an article when it is updated.

The modified date alone has one-second resolution, so a quick second edit could go unnoticed.

Since: 3.2.0
Line: 127

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 article whose terms changed, as they decide its related articles.

Since: 3.2.0
Line: 145

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 knowledge base term is edited or deleted.

Since: 3.2.0
Line: 165

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() static

Retire all cached answers, including externally cached transients.

Since: 3.2.0
Line: 176

static public function invalidate(  ): void;

Returns: void

invalidate_unanswered() static

Retire cached unanswered results, which new or updated articles may now answer.

Since: 3.2.0
Line: 185

static public function invalidate_unanswered(  ): void;

Returns: void

fingerprint() static

Fingerprint of an article as seen by Ask the Docs.

Since: 3.2.0
Line: 197

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 an article edited while the provider answers retires the answer.

Since: 3.2.0
Line: 211

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: 3.2.0
Line: 238

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: 3.2.0
Line: 297

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: 3.2.0
Line: 324

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: 3.2.0
Line: 340

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: 3.2.0
Line: 372

static public function delete_expired_locks(  ): void;

Returns: void

set() static

Cache an answer.

Since: 3.2.0
Line: 400

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: 3.2.0
Line: 435

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: 3.2.0
Line: 469

static public function get_key( string $question ): string;
Type Name Description
string $question Validated question.

Returns: string — Transient key.

get_content_version() static

Current knowledge base content version.

Since: 3.2.0
Line: 492

static public function get_content_version(  ): string;

Returns: string — Version.

get_publish_version() static

Current version for unanswered results.

Since: 3.2.0
Line: 503

static public function get_publish_version(  ): string;

Returns: string — Version.