Skip to main content

GravityView_Cache

Handle caching using transients for GravityView

Source: includes/class-cache.php:8

Details

  • Kind: class
  • Namespace: (global)

Properties

PropertyTypeDescription
$form_idsmixedForm ID, or array of Form IDs
$argsarrayExtra request parameters used to generate the query. This is used to generate the unique transient key.

Methods

MethodDescription
__construct()
add_hooks()Add actions for clearing out caches when entries are updated.
entry_status_changed()Force refreshing a cache when an entry is deleted.
entry_property_changed()Force refreshing a cache when an entry is deleted.
entry_updated()When an entry is updated, add the entry's form to the cache blocklist
entry_created()When an entry is created, add the entry's form to the cache blocklist
entry_added()Clear the cache when entries are added via GFAPI::add_entry().
get_key()Allow public access to get transient key
blocklist_add()Add form IDs to a "blocklist" to force the cache to be refreshed
blacklist_add()
blocklist_remove()Remove Form IDs from blocklist
blacklist_remove()
in_blacklist()Is a form ID in the cache blocklist?
in_blocklist()Is a form ID in the cache blocklist
get()Get transient result
set()Cache content as a transient.
delete()Delete cached transients based on form IDs
schedule_transient_cleanup()Schedule expired transient cleanup twice a day.
delete_expired_transients()Delete expired transients.
use_cache()Check whether to use cached results, if available

Method Reference

__construct()

function __construct( $form_ids=null, $args=[] )

Parameters

NameTypeDefaultDescription
$form_idsarray | intnullForm ID or array of form IDs used in a request
$argsarray[]Extra request parameters used to generate the query. This is used to generate the unique transient key.

Source: includes/class-cache.php:50

add_hooks()

function add_hooks()

Add actions for clearing out caches when entries are updated.

Source: includes/class-cache.php:67

entry_status_changed()

public function entry_status_changed( $lead_id, $property_value='', $previous_value='' )

Force refreshing a cache when an entry is deleted.

The gform_delete_lead action is called before the lead is deleted; we fetch the entry to find out the form ID so it can be added to the blocklist.

Parameters

NameTypeDefaultDescription
$lead_idintEntry ID
$property_valuestring''Previous value of the lead status passed by gform_update_status hook
$previous_valuestring''Previous value of the lead status passed by gform_update_status hook

Returns

  • void

Since: 1.5.1

Source: includes/class-cache.php:109

entry_property_changed()

public function entry_property_changed( $lead_id, $property_name='', $property_value='', $previous_value='' )

Force refreshing a cache when an entry is deleted.

The gform_delete_lead action is called before the lead is deleted; we fetch the entry to find out the form ID so it can be added to the blocklist.

Parameters

NameTypeDefaultDescription
$lead_idintThe Entry ID.
$property_namestring''The property that was updated.
$property_valuestring''The new value of the property that was updated.
$previous_valuestring''The previous property value before the update.

Returns

  • void

Since: 2.16.3

Source: includes/class-cache.php:155

entry_updated()

public function entry_updated( $form, $lead_id )

When an entry is updated, add the entry's form to the cache blocklist

Parameters

NameTypeDefaultDescription
$formarrayGF form array
$lead_idintEntry ID

Returns

  • void

Source: includes/class-cache.php:196

entry_created()

public function entry_created( $entry, $form )

When an entry is created, add the entry's form to the cache blocklist

We don't want old caches; when an entry is added, we want to clear the cache.

Parameters

NameTypeDefaultDescription
$entryarrayGF entry array
$formarrayGF form array

Returns

  • void

Source: includes/class-cache.php:218

entry_added()

public function entry_added( $entry, $form )

Clear the cache when entries are added via GFAPI::add_entry().

Parameters

NameTypeDefaultDescription
$entryarrayThe GF Entry array
$formarrayThe GF Form array

Returns

  • void

Source: includes/class-cache.php:239

get_key()

public function get_key()

Allow public access to get transient key

Returns

  • string — Transient key

Source: includes/class-cache.php:302

blocklist_add()

public function blocklist_add( $form_ids )

Add form IDs to a "blocklist" to force the cache to be refreshed

Parameters

NameTypeDefaultDescription
$form_idsint | arrayForm IDs to force to be updated

Returns

  • boolean — False if value was not updated and true if value was updated.

Source: includes/class-cache.php:326

blacklist_add()

public function blacklist_add( $form_ids )

Parameters

NameTypeDefaultDescription
$form_idsint | arrayForm IDs to force to be updated

Returns

  • bool — Whether the removal was successful

Deprecated: 2.14 (\GravityView_Cache::blocklist_add())

Source: includes/class-cache.php:367

blocklist_remove()

public function blocklist_remove( $form_ids )

Remove Form IDs from blocklist

Parameters

NameTypeDefaultDescription
$form_idsint | arrayForm IDs to remove

Returns

  • bool — Whether the removal was successful

Source: includes/class-cache.php:379

blacklist_remove()

public function blacklist_remove( $form_ids )

Parameters

NameTypeDefaultDescription
$form_idsint | arrayForm IDs to add

Returns

  • bool — Whether the removal was successful

Deprecated: 2.14 (\GravityView_Cache::blocklist_remove())

Source: includes/class-cache.php:412

in_blacklist()

public function in_blacklist( $form_ids=null )

Is a form ID in the cache blocklist?

Parameters

NameTypeDefaultDescription
$form_idsint | arraynullForm IDs to check if in blocklist

Returns

  • bool

Deprecated: 2.14 (Use \GravityView_Cache::in_blocklist())

Source: includes/class-cache.php:426

in_blocklist()

public function in_blocklist( $form_ids=null )

Is a form ID in the cache blocklist

Parameters

NameTypeDefaultDescription
$form_idsint | arraynullForm IDs to check if in blocklist

Returns

  • bool

Source: includes/class-cache.php:438

get()

public function get( $key=null )

Get transient result

Parameters

NameTypeDefaultDescription
$keystringnullTransient key to fetch

Returns

  • mixed — False: Not using cache or cache was a WP_Error object; NULL: no results found; Mixed: cache value

Source: includes/class-cache.php:473

set()

public function set( $content, $filter_name='', $expiration=null )

Cache content as a transient.

Cache time defaults to 1 day.

Parameters

NameTypeDefaultDescription
$contentmixedThe content to cache.
$filter_namestring''Name used to modify the cache time. Will be set to gravityview_cache_time_{$filter_name}.
$expirationint | nullnullCache time in seconds. If not set, DAYS_IN_SECONDS will be used.

Returns

  • bool — If $content is not set, false. Otherwise, returns true if transient was set and false if not.

Since: 2.16 (Added $cache_time parameter to allow overriding the default cache time.)

Source: includes/class-cache.php:519

delete()

public function delete( $form_ids=null )

Delete cached transients based on form IDs

Parameters

NameTypeDefaultDescription
$form_idsint | arraynullForm IDs to delete

Returns

  • void

Source: includes/class-cache.php:573

schedule_transient_cleanup()

public function schedule_transient_cleanup()

Schedule expired transient cleanup twice a day.

Can be overruled by the gravityview_cleanup_transients filter (returns boolean)

Returns

  • void

Source: includes/class-cache.php:621

delete_expired_transients()

public function delete_expired_transients()

Delete expired transients.

The code is copied from the Delete Expired Transients, with slight modifications to track # of results and to get the blog ID dynamically

Returns

  • void

See Also

Source: includes/class-cache.php:650

use_cache()

public function use_cache()

Check whether to use cached results, if available

If the user can edit posts, they are able to override whether to cache results by adding cache or nocache to the URL requested.

Returns

  • boolean — True: use cache; False: don't use cache

Source: includes/class-cache.php:709