Skip to main content

PDF for GravityView Hooks – gfpdf_gv_enable_pdf_cache

Description​

Use this filter to turn PDF caching on or off independently of GravityView's caching settings, which the PDF cache follows by default (see Caching). For example, stop caching PDFs on one View while GravityView keeps caching its entries.

The filter runs last, so the value you return wins:

  • If the GRAVITYVIEW_DISABLE_CACHE constant is defined and true, the filter receives false. Return true to cache PDFs anyway.
  • The cache and nocache query arguments (honored for users who can edit Views) and GravityView's gravityview_use_cache filter are applied before this filter, so your return value overrides them.

To change how long a cached PDF is kept, use gfpdf_gv_cache_ttl.

Version​

This hook was introduced in PDF for GravityView 2.0.

Arguments​

The following arguments are passed to functions that use this hook:

$use_cache | bool​

  • Whether to serve and store cached PDFs for this request.
  • The default value is the View's GravityView caching setting, or false when GRAVITYVIEW_DISABLE_CACHE is set.

$view | \GV\View​

  • The View the PDF is being generated for.

Usage​

Never cache PDFs for View 885:

add_filter( 'gfpdf_gv_enable_pdf_cache', function( $use_cache, $view ) {
if ( (int) $view->ID === 885 ) {
return false;
}

return $use_cache;
}, 10, 2 );

Keep caching PDFs when GRAVITYVIEW_DISABLE_CACHE turns off GravityView's cache:

add_filter( 'gfpdf_gv_enable_pdf_cache', '__return_true' );

Source Code​

This filter is located in src/Pdf/Caching/Cache.php of the PDF for GravityView extension.