GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
GravityView_Cache Class Reference

Handle caching using transients for GravityView. More...

Public Member Functions

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

Data Fields

const BLACKLIST_OPTION_NAME = 'gravityview_cache_blocklist'
 
const BLOCKLIST_OPTION_NAME = 'gravityview_cache_blocklist'
 

Protected Member Functions

 get_cache_key_prefix ( $form_ids=NULL)
 Calculate the prefix based on the Form IDs. More...
 
 set_key ()
 Set the transient key based on the form IDs and the arguments passed to the class. More...
 

Protected Attributes

 $args
 
 $form_ids
 

Private Member Functions

 blocklist_get ()
 Get the blocklist array. More...
 

Private Attributes

 $key = ''
 
 $use_cache = null
 Whether to use the cache or not. More...
 

Detailed Description

Handle caching using transients for GravityView.

Definition at line 6 of file class-cache.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $form_ids = NULL,
  $args = array() 
)
Parameters
array | int$form_idsForm ID or array of form IDs used in a request
array$argsExtra request parameters used to generate the query. This is used to generate the unique transient key.

Definition at line 46 of file class-cache.php.

References $args, $form_ids, add_hooks(), and set_key().

Member Function Documentation

◆ add_hooks()

add_hooks ( )

Add actions for clearing out caches when entries are updated.

Since
1.14

Definition at line 63 of file class-cache.php.

Referenced by __construct().

◆ blacklist_add()

blacklist_add (   $form_ids)
See also
GravityView_Cache::blocklist_add()}
Parameters
int | array$form_idsForm IDs to force to be updated
Returns
bool Whether the removal was successful

Definition at line 319 of file class-cache.php.

References $form_ids, and blocklist_remove().

◆ blacklist_remove()

blacklist_remove (   $form_ids)
See also
GravityView_Cache::blocklist_remove()}
Parameters
int | array$form_idsForm IDs to add
Returns
bool Whether the removal was successful

Definition at line 353 of file class-cache.php.

References $form_ids, and blocklist_remove().

◆ blocklist_add()

blocklist_add (   $form_ids)

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

Parameters
int | array$form_idsForm IDs to force to be updated
Returns
boolean False if value was not updated and true if value was updated.

Definition at line 283 of file class-cache.php.

References $form_ids, blocklist_get(), and gravityview().

Referenced by entry_added(), entry_created(), entry_property_changed(), entry_status_changed(), and entry_updated().

◆ blocklist_get()

blocklist_get ( )
private

Get the blocklist array.

Since
2.16.3
Returns
array

Definition at line 270 of file class-cache.php.

Referenced by blocklist_add(), and in_blocklist().

◆ blocklist_remove()

blocklist_remove (   $form_ids)

Remove Form IDs from blocklist.

Parameters
int | array$form_idsForm IDs to remove
Returns
bool Whether the removal was successful

Definition at line 331 of file class-cache.php.

References $form_ids, and gravityview().

Referenced by blacklist_add(), blacklist_remove(), and use_cache().

◆ delete()

delete (   $form_ids = NULL)

Delete cached transients based on form IDs.

Parameters
int | array$form_idsForm IDs to delete
Returns
void

Definition at line 499 of file class-cache.php.

References $form_id, $form_ids, $key, and gravityview().

◆ delete_expired_transients()

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

See also
https://wordpress.org/plugins/delete-expired-transients/ Plugin where the code was taken from
DelxtransCleaners::clearBlogExpired()
Returns
void

Definition at line 569 of file class-cache.php.

References gravityview().

◆ entry_added()

entry_added (   $entry,
  $form 
)

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

Parameters
array$entryThe GF Entry array
array$formThe GF Form array
Returns
void

Definition at line 201 of file class-cache.php.

References $entry, GV\$form, blocklist_add(), and gravityview().

◆ entry_created()

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
array$entryGF entry array
array$formGF form array
Returns
void

Definition at line 186 of file class-cache.php.

References $entry, GV\$form, blocklist_add(), and gravityview().

◆ entry_property_changed()

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.

Since
2.16.3
Parameters
int$lead_idThe Entry ID.
string$property_nameThe property that was updated.
string$property_valueThe new value of the property that was updated.
string$previous_valueThe previous property value before the update.
Returns
void

Definition at line 134 of file class-cache.php.

References $entry, blocklist_add(), and gravityview().

◆ entry_status_changed()

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.

Since
1.5.1
Parameters
int$lead_idEntry ID
string$property_valuePrevious value of the lead status passed by gform_update_status hook
string$previous_valuePrevious value of the lead status passed by gform_update_status hook
Returns
void

Definition at line 104 of file class-cache.php.

References $entry, blocklist_add(), and gravityview().

◆ entry_updated()

entry_updated (   $form,
  $lead_id 
)

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

Parameters
array$formGF form array
int$lead_idEntry ID
Returns
void

Definition at line 169 of file class-cache.php.

References GV\$form, blocklist_add(), and gravityview().

◆ get()

get (   $key = null)

Get transient result.

Parameters
string$keyTransient key to fetch
Returns
mixed False: Not using cache or cache was a WP_Error object; NULL: no results found; Mixed: cache value

Definition at line 414 of file class-cache.php.

References $key, gravityview(), and use_cache().

◆ get_cache_key_prefix()

get_cache_key_prefix (   $form_ids = NULL)
protected

Calculate the prefix based on the Form IDs.

Parameters
int | array$form_idsForm IDs to generate prefix for
Returns
string Prefix for the cache string used in set_key()

Definition at line 218 of file class-cache.php.

References $form_ids, and $forms.

Referenced by set_key().

◆ get_key()

get_key ( )

Allow public access to get transient key.

Returns
string Transient key

Definition at line 259 of file class-cache.php.

References $key.

◆ in_blacklist()

in_blacklist (   $form_ids = NULL)

Is a form ID in the cache blocklist?

Parameters
int | array$form_idsForm IDs to check if in blocklist
See also
GravityView_Cache::in_blocklist()}
Returns
bool

Definition at line 367 of file class-cache.php.

References $form_ids, and in_blocklist().

◆ in_blocklist()

in_blocklist (   $form_ids = NULL)

Is a form ID in the cache blocklist.

Parameters
int | array$form_idsForm IDs to check if in blocklist
Returns
bool

Definition at line 379 of file class-cache.php.

References $form_id, $form_ids, blocklist_get(), and gravityview().

Referenced by in_blacklist(), and use_cache().

◆ schedule_transient_cleanup()

schedule_transient_cleanup ( )

Schedule expired transient cleanup twice a day.

Can be overruled by the gravityview_cleanup_transients filter (returns boolean)

Returns
void
Runs Filter:
gravityview_cleanup_transients Override GravityView cleanup of transients by setting this to false
Parameters
boolean$cleanupWhether to run the GravityView auto-cleanup of transients. Default: true

Definition at line 543 of file class-cache.php.

◆ set()

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

Cache content as a transient.

Cache time defaults to 1 day.

Since
2.16 Added $cache_time parameter to allow overriding the default cache time.
Parameters
mixed$contentThe content to cache.
string$filter_nameName used to modify the cache time. Will be set to gravityview_cache_time_{$filter_name}.
int | null$expirationCache 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.
Runs Filter:
gravityview_cache_time_{$filter_name} Modify the cache time for a type of cache
Parameters
int$time_in_secondsDefault: DAY_IN_SECONDS

Definition at line 460 of file class-cache.php.

References $content, gravityview(), and use_cache().

Referenced by GravityView_Welcome\getting_started_screen().

◆ set_key()

set_key ( )
protected

Set the transient key based on the form IDs and the arguments passed to the class.

Definition at line 238 of file class-cache.php.

References $key, and get_cache_key_prefix().

Referenced by __construct().

◆ use_cache()

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
Runs Filter:
gravityview_use_cache Modify whether to use the cache or not
Parameters
boolean$use_cachePrevious setting
GravityView_Cache$thisThe GravityView_Cache object

Definition at line 619 of file class-cache.php.

References $form_ids, $use_cache, blocklist_remove(), gravityview(), GVCommon\has_cap(), and in_blocklist().

Referenced by get(), GravityView_Welcome\getting_started_screen(), and set().

Field Documentation

◆ $args

$args
protected

Definition at line 25 of file class-cache.php.

Referenced by __construct().

◆ $form_ids

$form_ids
protected

◆ $key

$key = ''
private

Definition at line 32 of file class-cache.php.

Referenced by delete(), get(), get_key(), and set_key().

◆ $use_cache

null boolean $use_cache = null
private

Whether to use the cache or not.

Set in {

See also
use_cache()}.

Definition at line 39 of file class-cache.php.

Referenced by use_cache().

◆ BLACKLIST_OPTION_NAME

const BLACKLIST_OPTION_NAME = 'gravityview_cache_blocklist'

Definition at line 9 of file class-cache.php.

◆ BLOCKLIST_OPTION_NAME

const BLOCKLIST_OPTION_NAME = 'gravityview_cache_blocklist'

Definition at line 11 of file class-cache.php.


The documentation for this class was generated from the following file: