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_CACHEconstant is defined and true, the filter receivesfalse. Returntrueto cache PDFs anyway. - The
cacheandnocachequery arguments (honored for users who can edit Views) and GravityView'sgravityview_use_cachefilter 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
falsewhenGRAVITYVIEW_DISABLE_CACHEis 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.