Cache
Cache Class.
Namespace: WebberZone\Contextual_Related_Posts\Util
Since: 3.5.0
Source: includes/util/class-cache.php line 23
Methods
__construct()
Constructor class.
Since: 3.5.0
Line: 51
public function __construct( );
clear_cache_on_save() static
Clear the saved post’s own cache and queue its related posts for clearing on shutdown.
Since: 4.5.0
Line: 66
static public function clear_cache_on_save( $post_id, $post, $update = ..., $post_before = ... ): void;
| Type | Name | Description |
|---|---|---|
int |
$post_id |
Post ID. |
\WP_Post|int |
$post |
Post object or post ID. |
bool |
$update |
Whether this is an update. |
\WP_Post|null |
$post_before |
Post object before the save, null for a new post. |
Returns: void
process_queue() static
Clear the cache of every post queued this request.
Runs on shutdown so the query sees the fully synced index: on a REST save the terms are set after wp_after_insert_post has already fired.
Since: 4.5.0
Line: 358
static public function process_queue( ): void;
Returns: void
deferred_flush() static
Flush the entire cache. Callback for the deferred flush scheduled after a bulk save.
Since: 4.5.0
Line: 506
static public function deferred_flush( ): void;
Returns: void
maybe_clear_cache_on_trash() static
Clear the CRP cache when a post is trashed or restored, if the option is enabled.
Since: 4.3.0
Line: 518
static public function maybe_clear_cache_on_trash( $post_id ): void;
| Type | Name | Description |
|---|---|---|
int |
$post_id |
Post ID being trashed or restored. |
Returns: void
ajax_clearcache() static
Function to clear the CRP Cache with Ajax.
Since: 3.5.0
Line: 538
static public function ajax_clearcache( );
delete() static
Delete the entire CRP cache.
Since: 3.5.0
Line: 575
static public function delete( ): int;
Returns: int — Number of keys deleted.
delete_by_post_ids() static
Delete the cache for an array of post IDs.
Since: 4.5.0
Line: 653
static public function delete_by_post_ids( array $post_ids ): int;
| Type | Name | Description |
|---|---|---|
array |
$post_ids |
Array of post IDs. |
Returns: int — Number of entries deleted.
get_status() static
Get cache status information.
Since: 4.2.0
Line: 725
static public function get_status( ): array;
Returns: array — Cache status information.
get_keys() static
Get array of cache keys.
Since: 3.5.0
Line: 754
static public function get_keys( ): array;
Returns: array — Array of cache keys.
get_meta_keys() static
Get the _crp_cache keys.
Since: 3.5.0
Line: 776
static public function get_meta_keys( $post_id = ... ): array;
| Type | Name | Description |
|---|---|---|
int |
$post_id |
Post ID. Optional. |
Returns: array — Array of _crp_cache keys.
cleanup_expired() static
Clean up expired cache entries.
Since: 4.2.0
Line: 810
static public function cleanup_expired( bool $dry_run = ... ): array;
| Type | Name | Description |
|---|---|---|
bool |
$dry_run |
Whether to perform a dry run. |
Returns: array — Results array with ‘cleaned’ and ‘scanned’ counts.
delete_by_post_id() static
Delete cache by post ID.
Since: 3.4.0
Line: 874
static public function delete_by_post_id( $post_id ): int;
| Type | Name | Description |
|---|---|---|
int |
$post_id |
Post ID. |
Returns: int — Number of entries deleted.
get_key() static
Get the cache key based on a list of parameters.
Since: 3.5.0
Line: 886
static public function get_key( $attr ): string;
| Type | Name | Description |
|---|---|---|
mixed |
$attr |
Array of attributes typically. |
Returns: string — Cache meta key
set_cache() static
Sets/updates the value of the CRP cache for a post.
Since: 3.5.0
Line: 1113
static public function set_cache( $post_id, $key, $value, $expiration = ..., string $cache_type = ..., array $args = ... ): int|bool;
| Type | Name | Description |
|---|---|---|
int |
$post_id |
Post ID. |
string |
$key |
CRP Cache key. |
mixed |
$value |
Metadata value. Must be serializable if non-scalar. |
int |
$expiration |
Time until expiration in seconds. Default CRP_CACHE_TIME (one month if not overridden). |
string |
$cache_type |
Cache type: ‘html’ or ‘posts’. Default: ‘html’. |
array |
$args |
Query arguments used to resolve a query-specific cache lifetime. |
Returns: int|bool — Meta ID if the key didn’t exist, true on successful update,
get_cache_time() static
Get the cache time to use.
Since: 4.0.0
Line: 1161
static public function get_cache_time( $key = ..., $post_id = ..., array $args = ... ): int;
| Type | Name | Description |
|---|---|---|
string |
$key |
CRP Cache key. |
int |
$post_id |
Post ID. |
array |
$args |
Query arguments used to resolve a query-specific cache lifetime. |
Returns: int — Cache time in seconds.
get_cache() static
Get the value of the CRP cache for a post.
Since: 3.5.0
Line: 1222
static public function get_cache( $post_id, $key, string $cache_type = ..., array $args = ... ): mixed;
| Type | Name | Description |
|---|---|---|
int |
$post_id |
Post ID. |
string |
$key |
CRP Cache key. |
string |
$cache_type |
Cache type: ‘html’ or ‘posts’. Default: ‘html’. |
array |
$args |
Query arguments used to resolve a query-specific cache lifetime. |
Returns: mixed — Value of the CRP cache or false if invalid, expired or unavailable.
delete_by_post_id_and_key() static
Delete the value of the CRP cache for a post.
Since: 3.5.0
Line: 1259
static public function delete_by_post_id_and_key( $post_id, $key, string $cache_type = ... ): bool;
| Type | Name | Description |
|---|---|---|
int |
$post_id |
Post ID. |
string |
$key |
CRP Cache key. |
string |
$cache_type |
Cache type: ‘html’, ‘posts’, or ‘all’. Default: ‘all’. |
Returns: bool — True on success, False on failure.
delete_by_key() static
Delete the value of the CRP cache by cache key.
Since: 3.5.0
Line: 1294
static public function delete_by_key( $key, string $cache_type = ... ): bool;
| Type | Name | Description |
|---|---|---|
string |
$key |
CRP Cache key. |
string |
$cache_type |
Cache type: ‘html’, ‘posts’, or ‘all’. Default: ‘all’. |
Returns: bool — True on success, False on failure.