WooCommerce Code Reference

WC_Cache_Helper
in package
Uses CacheNameSpaceTrait

WC_Cache_Helper.

Table of Contents

$delete_transients  : array<string|int, mixed>
Transients to delete on shutdown.
additional_nocache_headers()  : mixed
Set additional nocache headers.
clean_term_cache()  : mixed
Clean term caches added by WooCommerce.
delete_transients_on_shutdown()  : mixed
Transients that don't need to be cleaned right away can be deleted on shutdown to avoid repetition.
delete_version_transients()  : mixed
When the transient version increases, this is used to remove all past transients to avoid filling the DB.
geolocation_ajax_get_location_hash()  : string
Get a hash of the customer location.
geolocation_ajax_redirect()  : mixed
When using geolocation via ajax, to bust cache, redirect if the location hash does not equal the querystring.
get_cache_prefix()  : string
Get prefix for use with wp_cache_set. Allows all cache in a group to be invalidated at once.
get_prefixed_key()  : string
Helper method to get prefixed key.
get_transient_version()  : string
Get transient version.
incr_cache_prefix()  : mixed
Increment group cache prefix (invalidates cache).
init()  : mixed
Hook in methods.
invalidate_attribute_count()  : mixed
Used to clear layered nav counts based on passed attribute names.
invalidate_cache_group()  : mixed
Invalidate cache group.
notices()  : mixed
Notices function.
prevent_caching()  : mixed
Prevent caching on certain pages
queue_delete_transient()  : mixed
Add a transient to delete on shutdown.
set_nocache_constants()  : mixed
Set constants to prevent caching by some plugins.
update_geolocation_hash()  : mixed
Updates the `woocommerce_geo_hash` cookie, which is used to help ensure we display the correct pricing etc to customers, according to their billing country.

Properties

Methods

additional_nocache_headers()

Set additional nocache headers.

public static additional_nocache_headers(array<string|int, mixed> $headers) : mixed
Parameters
$headers : array<string|int, mixed>

Header names and field values.

Tags
since
3.6.0
Return values
mixed

clean_term_cache()

Clean term caches added by WooCommerce.

public static clean_term_cache(array<string|int, mixed>|int $ids, string $taxonomy) : mixed
Parameters
$ids : array<string|int, mixed>|int

Array of ids or single ID to clear cache for.

$taxonomy : string

Taxonomy name.

Tags
since
3.3.4
Return values
mixed

delete_transients_on_shutdown()

Transients that don't need to be cleaned right away can be deleted on shutdown to avoid repetition.

public static delete_transients_on_shutdown() : mixed
Tags
since
3.6.0
Return values
mixed

delete_version_transients()

When the transient version increases, this is used to remove all past transients to avoid filling the DB.

public static delete_version_transients([string $version = '' ]) : mixed

Note; this only works on transients appended with the transient version, and when object caching is not being used.

Parameters
$version : string = ''

Version of the transient to remove.

Tags
deprecated
3.6.0

Adjusted transient usage to include versions within the transient values, making this cleanup obsolete.

since
2.3.10
Return values
mixed

geolocation_ajax_get_location_hash()

Get a hash of the customer location.

public static geolocation_ajax_get_location_hash() : string
Return values
string

geolocation_ajax_redirect()

When using geolocation via ajax, to bust cache, redirect if the location hash does not equal the querystring.

public static geolocation_ajax_redirect() : mixed

This prevents caching of the wrong data for this request.

Return values
mixed

get_cache_prefix()

Get prefix for use with wp_cache_set. Allows all cache in a group to be invalidated at once.

public static get_cache_prefix(string $group) : string
Parameters
$group : string

Group of cache to get.

Return values
stringPrefix.

get_prefixed_key()

Helper method to get prefixed key.

public static get_prefixed_key(string $key, string $group) : string
Parameters
$key : string

Key to prefix.

$group : string

Group of cache to get.

Return values
stringPrefixed key.

get_transient_version()

Get transient version.

public static get_transient_version(string $group[, bool $refresh = false ]) : string

When using transients with unpredictable names, e.g. those containing an md5 hash in the name, we need a way to invalidate them all at once.

When using default WP transients we're able to do this with a DB query to delete transients manually.

With external cache however, this isn't possible. Instead, this function is used to append a unique string (based on time()) to each transient. When transients are invalidated, the transient version will increment and data will be regenerated.

Raised in issue https://github.com/woocommerce/woocommerce/issues/5777. Adapted from ideas in http://tollmanz.com/invalidation-schemes/.

Parameters
$group : string

Name for the group of transients we need to invalidate.

$refresh : bool = false

true to force a new version.

Return values
stringtransient version based on time(), 10 digits.

incr_cache_prefix()

Increment group cache prefix (invalidates cache).

public static incr_cache_prefix(string $group) : mixed
Parameters
$group : string

Group of cache to clear.

Return values
mixed

invalidate_attribute_count()

Used to clear layered nav counts based on passed attribute names.

public static invalidate_attribute_count(array<string|int, mixed> $attribute_keys) : mixed
Parameters
$attribute_keys : array<string|int, mixed>

Attribute keys.

Tags
since
3.6.0
Return values
mixed

invalidate_cache_group()

Invalidate cache group.

public static invalidate_cache_group(string $group) : mixed
Parameters
$group : string

Group of cache to clear.

Tags
since
3.9.0
Return values
mixed

queue_delete_transient()

Add a transient to delete on shutdown.

public static queue_delete_transient(string|array<string|int, mixed> $keys) : mixed
Parameters
$keys : string|array<string|int, mixed>

Transient key or keys.

Tags
since
3.6.0
Return values
mixed

set_nocache_constants()

Set constants to prevent caching by some plugins.

public static set_nocache_constants([mixed $return = true ]) : mixed
Parameters
$return : mixed = true

Value to return. Previously hooked into a filter.

Return values
mixed

update_geolocation_hash()

Updates the `woocommerce_geo_hash` cookie, which is used to help ensure we display the correct pricing etc to customers, according to their billing country.

public static update_geolocation_hash() : mixed

Note that:

A) This only sets the cookie if the default customer address is set to "Geolocate (with Page Caching Support)".

B) It is hooked into the wc_ajax_update_order_review action, which has the benefit of ensuring we update the cookie any time the billing country is changed.

Return values
mixed