ProCache API

The ultimate caching and optimization tool for ProcessWire.

ProcessWire ProCache is the ultimate cache and optimization tool for ProcessWire powered websites. It provides static cache page delivery, CDN, SCSS/LESS compilers, CSS merge/minify, JS merge/minify, HTML minify, asset busters, optimization tweaks, .htaccess optimization, live tests and more. This documentation page provides details on the most common ProCache API methods and properties. More about ProCache.


Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the ProCache class also inherits all the methods and properties of: WireData and Wire.

Show $var?     Show args?       Only hookable?    

Status

NameReturnSummary 
$procache->allowCacheForPage(Page $page)
bool

Hookable method to allow custom rules to determine if page output should be saved to cache file for this request

$procache->cacheMaintenance()
int array

Run cache maintenance

 
$procache->cacheOn()
bool

Get or set cache on/off status

 
$procache->getCachePath()
string

Return the path where we store cache files (optionally for a specific page)

 
$procache->hasCacheFile(Page $page)
bool string

Get cache file for given Page (and options) or false if does not currently have a cache file

 
$procache->isPageCacheable(Page $page)
bool

Is given page configured for caching in ProCache?

 
$procache->numCachedPages()
int

Return the total number of pages in the cache

 
$procache->pageInfo(Page $page)
array bool

Get an array about the page’s ProCache info or false if caching is not enabled for page

 
$procache->setRenderPage($page)
None

Set the page that is being rendered, if different from current $page API variable

 

Origin

NameReturnSummary 
$procache->cacheHosts array Host names that should be cached separately.
DEFAULT: []
 
$procache->cacheTemplates array IDs of templates where caching is enabled.
DEFAULT: []
 
$procache->docRootPath string Server document root path for .htaccess file for when %{DOCUMENT_ROOT} does not work  
$procache->https int Cache https and http requests separately, specify 1 or true for yes or 0 or false for no.
DEFAULT: 0
 
$procache->urlSegments int Max URL segments to cache
DEFAULT: 0
 

Lifespan

NameReturnSummary 
$procache->cacheTime int Default lifetime of cache files in seconds
DEFAULT: 3600
 
$procache->cacheTimeCustom string Custom cache time settings per template, as specified in ProCache admin.  
$procache->getCacheTime()
array int string

Get the cache time for the given Template, or for all templates

 

Behavior

NameReturnSummary 
$procache->cacheClear array Default cache clear behaviors, one or more CACHE_CLEAR_* constant values.  
$procache->cacheClearCustom string Custom settings for cache clearing as specified in the ProCache admin.  
$procache->cacheClearOff array Default bypasses of cache clear behaviors, one or more CACHE_CLEAR_OFF_* constant values.  
$procache->getCacheClearBehaviors()
array

Get the cache clearing behaviors for all templates or a given template

 

Bypass

NameReturnSummary 
$procache->noCacheCookies string bool Disable use of cache when these cookie names are present. Newline separated list of cookie names, or boolean false for default which represents current logged-in cookies.
DEFAULT: false
 
$procache->noCacheGetVars string Newline separated list of GET variable names that skip the cache or * for any
DEFAULT: *
 

Minify

NameReturnSummary 
$procache->assetExpireTime int Expire CSS or JS merge/minify assets after this amount of time
DEFAULT: 0
 
$procache->css($files)
string

Merge and minify the given array or CSV string of CSS, SCSS or LESS file URLs

 
$procache->js($files)
string

Merge and minify the given array or CSV string of Javascript file URLs

 
$procache->link($files)
string

Generate an HTML stylesheet <link> tag with the given CSS/LESS/SCSS file URLs

 
$procache->merge($files)
string

Merge the given array or CSV string of file URLs and returned the merged file URL

 
$procache->minify ProCacheMinify Access methods from ProCacheMinify instance  
$procache->minifyBlocks string HTML tags to treat as block level elements for collapsing whitespace.
DEFAULT: p h1 h2 h3 h4 div pre more…
 
$procache->minifyHTML ProCacheMinifyHTML Access methods from ProCacheMinifyHTML instance  
$procache->minifyHTMLOptions array Addititional minify HTML options/toggles as specified in ProCache admin.  
$procache->minifyHtml(string $html)
bool

Minify given HTML directly

 
$procache->minifyIgnoreTags string Space separated HTML tags that should be ignored during HTML minification
DEFAULT: textarea pre svg
 
$procache->minifyMaxImportCSS int Max kilobytes to allow for files encoded directly into the CSS
DEFAULT: 5
 
$procache->minifyOptions array Minify options/toggles: htmlGuest, htmlUsers, htmlCache, jsHead, jsBody, cssHead, useTemplates  
$procache->minifyRemoveBlankAttr string Space separated HTML attribute names that when blank may be removed
DEFAULT: class dir for id lang style title
 
$procache->minifyTemplates array IDs of templates where HTML minify is enabled.
DEFAULT: []
 
$procache->script($files)
string

Generate an HTML Javascript <script> tag with the given files merged

 

CDN

NameReturnSummary 
$procache->allowCDN()
bool

Is CDN active/allowed for current page/request/user?

 
$procache->cdn ProCacheCDN Access methods from ProCacheCDN instance  
$procache->cdnAttrs string Space-separated HTML attributes that can contain URLs that should be converted to CDN. .
DEFAULT: src srcset href
 
$procache->cdnExts string Space-separated rile extensions that should be delivered by the CDN, or blank for all file extension.
DEFAULT: css js jpg jpeg gif png svg webp
 
$procache->cdnHosts string One or more lines of: “/path/=your.cdn.com”, where “/path/” is the local starting path (pull origin) you want served by the CDN (typically /site/), and “your.cdn.com” is the CDN hostname (and optionally path) you want to map those assets to.  
$procache->cdnStatus int CDN status (0=Off, 1=On for guests only, 2=On for logged-in users only, 3=On for everyone)
DEFAULT: 0
 
$procache->cdnTemplates array Template IDs used by pages that should have assets delivered by CDN or empty for all applicable
DEFAULT: []
 
$procache->cdnUrl(string $url)
string

Given a local URL convert to a CDN URL (if given URL is in CDN’s path space)

 
$procache->populateCDN(string $content)
bool

Populate CDN replacements into given content string regardless of whether it’s enabled

 
$procache->renderCDN($page, string $content)
bool

Populate CDN replacements into given content string but only if CDN is enabled and allowed for given $page

 

Buster

NameReturnSummary 
$procache->buster ProCacheBuster Access methods from ProCacheBuster instance  
$procache->busterUrlType string Buster URL type:
A=/url/to/file.ext?version,
B=/url/to/file.ext?v=version,
C=/url/to/file.version.ext
DEFAULT: A
 

Tweaks

NameReturnSummary 
$procache->bodyClass string Class name to add to class attribute of <body> tag when cache is enabled
DEFAULT: ProCache
 
$procache->canonical int string Use canonical link tag?
0 No,
1 Yes with current scheme,
http Yes w/HTTP scheme,
https Yes w/HTTPS scheme
 
$procache->debug bool Enable ProCache debug mode? Includes HTML comment at bottom of output with details of cache info.
DEFAULT: false
 
$procache->htNoEx int bool Prevent example .htaccess files from being created?
DEFAULT: false
 
$procache->htVersion int Htaccess type/version to use. 1=original/long, 2=short
DEFAULT: 2
 
$procache->noMaintenance bool Set to true at runtime to prevent maintenance from running when it usually does.
DEFAULT: false
 
$procache->scssType string SCSS compiler to use: 'leafo-1.11.0', 'leafo-1.12.1', 'leafo-2.0.1' or blank for auto  
$procache->slashUrls int Require URLs to have trailing slash?
1 yes slash,
0 either,
-1 no slash
 
$procache->tweaks ProCacheTweaks Access methods from ProCacheTweaks instance  

Clearing

NameReturnSummary 
$procache->cacheClear array Default cache clear behaviors, one or more CACHE_CLEAR_* constant values.  
$procache->cacheClearCustom string Custom settings for cache clearing as specified in the ProCache admin.  
$procache->clearAll()
int

Clear entire cache

$procache->clearPage(Page $page)
int array

Clear the cache for a specific page (including pageNum and urlSegment versions)

 
$procache->clearPages(PageArray $items)
array int

Clear the cache for multiple pages

 
$procache->tmpDirCleanup()
int

Cleanup any 'ProCache-tmp' dirs that remain in /site/assets/

 

Helpers

NameReturnSummary 
$procache->buster ProCacheBuster Access methods from ProCacheBuster instance  
$procache->cdn ProCacheCDN Access methods from ProCacheCDN instance  
$procache->files ProCacheFiles Access methods from ProCacheFiles instance  
$procache->getBuster()
ProCacheBuster

Get ProCacheBuster instance

 
$procache->getCDN()
ProCacheCDN

Get instance of ProCacheCDN

 
$procache->getCompilerLESS()
mixed

Get instanceof LESS compiler

 
$procache->getCompilerSCSS()
ProCacheCompilerSCSS

Get instance of SCSS/SASS compiler

 
$procache->getFileMerger()
ProCacheFileMerger

Get an instance of the ProCache file merger

 
$procache->getFiles()
ProCacheFiles

Get instance of ProCacheFiles

 
$procache->getHooker()
ProCacheHooker

Get instance of ProCacheHooker, the class that hooks into ProcessWire

 
$procache->getHtaccess()
ProCacheHtaccess

Get instance of ProCacheHtaccess

 
$procache->getMinify()
ProCacheMinify

Get instance of ProCacheMinify, the class that manages HTML/CSS/JS minification

 
$procache->getMinifyHTML()
ProCacheMinifyHTML

Get instance of ProCacheMinifyHTML, the class that handles HTML minification

 
$procache->getStatic()
ProCacheStatic

Get instance of ProCacheStatic, the class that manages the static cache

 
$procache->getTests()
ProCacheTests

Get instance of ProCacheTests

 
$procache->getTweaks()
ProCacheTweaks

Get instance of ProCacheTweaks

 
$procache->hooker ProCacheHooker Access methods from ProCacheHooker instance  
$procache->htaccess ProCacheHtaccess Access methods from ProCacheHtaccess instance  
$procache->minify ProCacheMinify Access methods from ProCacheMinify instance  
$procache->minifyHTML ProCacheMinifyHTML Access methods from ProCacheMinifyHTML instance  
$procache->static ProCacheStatic Access methods from ProCacheStatic instance  
$procache->tests ProCacheTests Get instance of ProCacheTests class  
$procache->tweaks ProCacheTweaks Access methods from ProCacheTweaks instance  

Properties

NameReturnSummary 
$procache->minifyVersion string Minifier version to use, one of "legacy" or "latest"
DEFAULT: legacy
 

Constants

NameReturnSummary 
ProCache::CACHE_CLEAR_CHILDREN const1Cache clear: clear children 
ProCache::CACHE_CLEAR_FAMILY const7Cache clear: Family (page, parent, siblings, children, grandchildren, and so on…) 
ProCache::CACHE_CLEAR_HOME const3Cache clear: clear homepage 
ProCache::CACHE_CLEAR_NOSELF const9Cache clear: No self (overrides CACHE_CLEAR_SELF) 
ProCache::CACHE_CLEAR_OFF_SITE const3Cache clear off: Do not clear cache when page is saved from API rather than interactive/admin 
ProCache::CACHE_CLEAR_OFF_SYSTEM const2Cache clear off: Do not clear cache when system page is saved 
ProCache::CACHE_CLEAR_OFF_TEMPLATE const1Cache clear off: Do not clear cache when saved page uses template not itself configured for ProCache 
ProCache::CACHE_CLEAR_PAGES const5Cache clear: clear specific page IDs 
ProCache::CACHE_CLEAR_PARENTS const2Cache clear: clear all parents, except homepage 
ProCache::CACHE_CLEAR_REFERENCES const8Cache clear: Page references that refer to page 
ProCache::CACHE_CLEAR_REFERENCING const11Cache clear: Pages that page has references to Note: Values above 9 should use the same double digits, i.e. 11, 22, 33 
ProCache::CACHE_CLEAR_SELECTOR const6Cache clear: clear pages matching selector 
ProCache::CACHE_CLEAR_SELF const0Cache clear: clear self (note: this is always assumed) 
ProCache::CACHE_CLEAR_SITE const4Cache clear: clear entire site 
ProCache::CDN_STATUS_ALL const3CDN statuses: Enabled for everyone 
ProCache::CDN_STATUS_GUEST const1CDN statuses: Enabled for guest users only (disalbed for logged in users) 
ProCache::CDN_STATUS_OFF const0CDN statuses: OFF 
ProCache::CDN_STATUS_USERS const2CDN statuses: Enabled for logged-in users only 
ProCache::MAINTENANCE_SECONDS const30Number of seconds between maintenance runs 
ProCache::MAX_PAGE_NUM const1000Max number of URL-based page numbers that are supported per page (where template allows) 
ProCache::MIN_PW_VERSION const3.0.200Minimum ProcessWire version to run ProCache 

Additional methods and properties

In addition to the methods and properties above, ProCache also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.253