GravityView  2.10.1
The best, easiest way to display Gravity Forms entries on your website.
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes | 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)
 Add form IDs to a "blacklist" to force the cache to be refreshed. More...
 
 blacklist_remove ( $form_ids)
 Remove Form IDs from blacklist. 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 blacklist. 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 blacklist. 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 blacklist. More...
 
 schedule_transient_cleanup ()
 Schedule expired transient cleanup twice a day. More...
 
 set ( $content, $filter_name='')
 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_blacklist'
 

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 Attributes

 $key = ''
 
 $lead_db_columns = array( 'id', 'form_id', 'post_id', 'date_created', 'is_starred', 'is_read', 'ip', 'source_url', 'user_agent', 'currency', 'payment_status', 'payment_date', 'payment_amount', 'transaction_id', 'is_fulfilled', 'created_by', 'transaction_type', 'status' )
 

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 42 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
See also
RGFormsModel::update_lead_property() Trigger when any entry property changes

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

Referenced by __construct().

◆ blacklist_add()

blacklist_add (   $form_ids)

Add form IDs to a "blacklist" 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 231 of file class-cache.php.

References $form_ids, and gravityview().

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

◆ blacklist_remove()

blacklist_remove (   $form_ids)

Remove Form IDs from blacklist.

Parameters
int | array$form_idsForm IDs to add
Returns
boolean Whether the removal was successful

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

References $form_ids, and gravityview().

Referenced by 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 400 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 470 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 160 of file class-cache.php.

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

◆ entry_created()

entry_created (   $entry,
  $form 
)

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

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 145 of file class-cache.php.

References $entry, GV\$form, blacklist_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 blacklist.

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, blacklist_add(), and gravityview().

◆ entry_updated()

entry_updated (   $form,
  $lead_id 
)

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

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

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

References GV\$form, blacklist_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 323 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 177 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 218 of file class-cache.php.

References $key.

◆ in_blacklist()

in_blacklist (   $form_ids = NULL)

Is a form ID in the cache blacklist.

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

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

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

Referenced by 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 444 of file class-cache.php.

◆ set()

set (   $content,
  $filter_name = '' 
)

Cache content as a transient.

Cache time defaults to 1 week

Parameters
mixed$content[description]
string$filter_nameName used to modify the cache time. Will be set to gravityview_cache_time_{$filter_name}.
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 367 of file class-cache.php.

References $content, and gravityview().

◆ set_key()

set_key ( )
protected

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

Definition at line 197 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
[in,out]boolean$use_cachePrevious setting
[out]GravityView_Cache$thisThe GravityView_Cache object

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

References $form_ids, blacklist_remove(), gravityview(), GVCommon\has_cap(), and in_blacklist().

Referenced by get().

Field Documentation

◆ $args

$args
protected

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

Referenced by __construct().

◆ $form_ids

$form_ids
protected

◆ $key

$key = ''
private

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

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

◆ $lead_db_columns

$lead_db_columns = array( 'id', 'form_id', 'post_id', 'date_created', 'is_starred', 'is_read', 'ip', 'source_url', 'user_agent', 'currency', 'payment_status', 'payment_date', 'payment_amount', 'transaction_id', 'is_fulfilled', 'created_by', 'transaction_type', 'status' )
private

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

◆ BLACKLIST_OPTION_NAME

const BLACKLIST_OPTION_NAME = 'gravityview_cache_blacklist'

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


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