$procache
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.
Status
Origin
| Name | Return | Summary | |
|---|---|---|---|
| $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
| Name | Return | Summary | |
|---|---|---|---|
| $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() $procache->getCacheTime() $procache->getCacheTime($template = null) | array int string | Get the cache time for the given Template, or for all templates |
Behavior
| Name | Return | Summary | |
|---|---|---|---|
| $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() $procache->getCacheClearBehaviors() $procache->getCacheClearBehaviors($options = []) | array | Get the cache clearing behaviors for all templates or a given template |
Bypass
| Name | Return | Summary | |
|---|---|---|---|
| $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
| Name | Return | Summary | |
|---|---|---|---|
| $procache->assetExpireTime | int | Expire CSS or JS merge/minify assets after this amount of time DEFAULT: 0 | |
$procache->css() $procache->css($files) $procache->css($files, bool $minify = true) | string | Merge and minify the given array or CSV string of CSS, SCSS or LESS file URLs | |
$procache->js() $procache->js($files) $procache->js($files, bool $minify = true) | string | Merge and minify the given array or CSV string of Javascript file URLs | |
$procache->link() $procache->link($files) $procache->link($files, bool $minify = true, string $media = '') | string | Generate an HTML stylesheet | |
$procache->merge() $procache->merge($files) $procache->merge($files, bool $minify = true) | 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() $procache->minifyHtml(string $html) $procache->minifyHtml(string $html, array $options = [], bool $debug = false) | 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() $procache->script($files) $procache->script($files, bool $minify = true, string $type = '') | string | Generate an HTML Javascript |
CDN
| Name | Return | Summary | |
|---|---|---|---|
$procache->allowCDN() $procache->allowCDN() $procache->allowCDN($page = null) | 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() $procache->cdnUrl(string $url) $procache->cdnUrl(string $url, bool $requireExt = true) | string | Given a local URL convert to a CDN URL (if given URL is in CDN’s path space) | |
$procache->populateCDN() $procache->populateCDN(string $content) $procache->populateCDN(string $content, string $type = 'html') | bool | Populate CDN replacements into given content string regardless of whether it’s enabled | |
$procache->renderCDN() $procache->renderCDN($page, string $content) $procache->renderCDN($page, string $content, string $type = 'html') | bool | Populate CDN replacements into given content string but only if CDN is enabled and allowed for given $page |
Buster
| Name | Return | Summary | |
|---|---|---|---|
| $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
| Name | Return | Summary | |
|---|---|---|---|
| $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
| Name | Return | Summary | |
|---|---|---|---|
| $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() $procache->clearAll() $procache->clearAll() | int | Clear entire cache | |
$procache->clearPage() $procache->clearPage(Page $page) $procache->clearPage(Page $page, array $options = []) | int array | Clear the cache for a specific page (including pageNum and urlSegment versions) | |
$procache->clearPages() $procache->clearPages(PageArray $items) $procache->clearPages(PageArray $items, bool $getFiles = true) | array int | Clear the cache for multiple pages | |
$procache->tmpDirCleanup() $procache->tmpDirCleanup() $procache->tmpDirCleanup() | int | Cleanup any 'ProCache-tmp' dirs that remain in /site/assets/ |
Helpers
| Name | Return | Summary | |
|---|---|---|---|
| $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() $procache->getBuster() $procache->getBuster() | ProCacheBuster | Get ProCacheBuster instance | |
$procache->getCDN() $procache->getCDN() $procache->getCDN() | ProCacheCDN | Get instance of ProCacheCDN | |
$procache->getCompilerLESS() $procache->getCompilerLESS() $procache->getCompilerLESS() | mixed | Get instanceof LESS compiler | |
$procache->getCompilerSCSS() $procache->getCompilerSCSS() $procache->getCompilerSCSS() | ProCacheCompilerSCSS | Get instance of SCSS/SASS compiler | |
$procache->getFileMerger() $procache->getFileMerger() $procache->getFileMerger() | ProCacheFileMerger | Get an instance of the ProCache file merger | |
$procache->getFiles() $procache->getFiles() $procache->getFiles() | ProCacheFiles | Get instance of ProCacheFiles | |
$procache->getHooker() $procache->getHooker() $procache->getHooker() | ProCacheHooker | Get instance of ProCacheHooker, the class that hooks into ProcessWire | |
$procache->getHtaccess() $procache->getHtaccess() $procache->getHtaccess() | ProCacheHtaccess | Get instance of ProCacheHtaccess | |
$procache->getMinify() $procache->getMinify() $procache->getMinify() | ProCacheMinify | Get instance of ProCacheMinify, the class that manages HTML/CSS/JS minification | |
$procache->getMinifyHTML() $procache->getMinifyHTML() $procache->getMinifyHTML() | ProCacheMinifyHTML | Get instance of ProCacheMinifyHTML, the class that handles HTML minification | |
$procache->getStatic() $procache->getStatic() $procache->getStatic() | ProCacheStatic | Get instance of ProCacheStatic, the class that manages the static cache | |
$procache->getTests() $procache->getTests() $procache->getTests() | ProCacheTests | Get instance of ProCacheTests | |
$procache->getTweaks() $procache->getTweaks() $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 |
Debug
| Name | Return | Summary | |
|---|---|---|---|
$procache->consoleError() $procache->consoleError($a) $procache->consoleError($a, string $b = null) | array | Record error to javascript console (console.error) | |
$procache->consoleLog() $procache->consoleLog($a) $procache->consoleLog($a, string $b = null) | array | Log message to javacript console (console.log) | |
$procache->debugInfo() $procache->debugInfo() $procache->debugInfo(string $value = '', bool $prepend = false) | array | Add or get debug info | |
$procache->debugMode() $procache->debugMode() $procache->debugMode() | bool | Is ProCache in debug mode? |
Properties
| Name | Return | Summary | |
|---|---|---|---|
| $procache->minifyVersion | string | Minifier version to use, one of "legacy" or "latest" DEFAULT: legacy |
Constants
| Name | Return | Summary | |
|---|---|---|---|
| ProCache::CACHE_CLEAR_CHILDREN const | 1 | Cache clear: clear children | |
| ProCache::CACHE_CLEAR_FAMILY const | 7 | Cache clear: Family (page, parent, siblings, children, grandchildren, and so on…) | |
| ProCache::CACHE_CLEAR_HOME const | 3 | Cache clear: clear homepage | |
| ProCache::CACHE_CLEAR_NOSELF const | 9 | Cache clear: No self (overrides CACHE_CLEAR_SELF) | |
| ProCache::CACHE_CLEAR_OFF_SITE const | 3 | Cache clear off: Do not clear cache when page is saved from API rather than interactive/admin | |
| ProCache::CACHE_CLEAR_OFF_SYSTEM const | 2 | Cache clear off: Do not clear cache when system page is saved | |
| ProCache::CACHE_CLEAR_OFF_TEMPLATE const | 1 | Cache clear off: Do not clear cache when saved page uses template not itself configured for ProCache | |
| ProCache::CACHE_CLEAR_PAGES const | 5 | Cache clear: clear specific page IDs | |
| ProCache::CACHE_CLEAR_PARENTS const | 2 | Cache clear: clear all parents, except homepage | |
| ProCache::CACHE_CLEAR_REFERENCES const | 8 | Cache clear: Page references that refer to page | |
| ProCache::CACHE_CLEAR_REFERENCING const | 11 | Cache 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 const | 6 | Cache clear: clear pages matching selector | |
| ProCache::CACHE_CLEAR_SELF const | 0 | Cache clear: clear self (note: this is always assumed) | |
| ProCache::CACHE_CLEAR_SITE const | 4 | Cache clear: clear entire site | |
| ProCache::CDN_STATUS_ALL const | 3 | CDN statuses: Enabled for everyone | |
| ProCache::CDN_STATUS_GUEST const | 1 | CDN statuses: Enabled for guest users only (disalbed for logged in users) | |
| ProCache::CDN_STATUS_OFF const | 0 | CDN statuses: OFF | |
| ProCache::CDN_STATUS_USERS const | 2 | CDN statuses: Enabled for logged-in users only | |
| ProCache::MAINTENANCE_SECONDS const | 30 | Number of seconds between maintenance runs | |
| ProCache::MAX_PAGE_NUM const | 1000 | Max number of URL-based page numbers that are supported per page (where template allows) | |
| ProCache::MIN_PW_VERSION const | 3.0.200 | Minimum 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.261