Cache
Cache Class.
Namespace: WebberZone\Contextual_Related_Posts\Util
Since: 3.5.0
Source: includes/util/class-cache.php line 21
Methods
__construct()
Constructor class.
Since: 3.5.0
Line: 28
public function __construct( );
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: 40
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: 60
static public function ajax_clearcache( );
delete() static
Delete the entire CRP cache.
Since: 4.0.0
Line: 97
static public function delete( ): int;
Returns: int — Number of keys deleted.
get_status() static
Get cache status information.
Since: 4.2.0
Line: 167
static public function get_status( ): array;
Returns: array — Cache status information.
get_keys() static
Get array of cache keys.
Since: 3.5.0
Line: 196
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: 218
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: 252
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: 318
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: 348
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: 556
static public function set_cache( $post_id, $key, $value, $expiration = ..., string $cache_type = ... ): 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’. |
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: 603
static public function get_cache_time( $key = ..., $post_id = ... ): int;
| Type | Name | Description |
|---|---|---|
string | $key | CRP Cache key. |
int | $post_id | Post ID. |
Returns: int — Cache time in seconds.
get_cache() static
Get the value of the CRP cache for a post.
Since: 3.5.0
Line: 647
static public function get_cache( $post_id, $key, string $cache_type = ... ): mixed;
| Type | Name | Description |
|---|---|---|
int | $post_id | Post ID. |
string | $key | CRP Cache key. |
string | $cache_type | Cache type: ‘html’ or ‘posts’. Default: ‘html’. |
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: 684
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: 719
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.