GoAdmio

cache

Generate the PHP page-cache script for one domain or all domains from their cache settings

On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also


Overview

/go/cache builds the page-cache script of a domain from the cache settings saved for it in GoAdmio. A cached page is a copy of the finished HTML that is served again without running the site's PHP code, which makes repeat visits faster and reduces server load.

The command:

It does not delete cached pages. See Clearing the cache.


Quick start

# Rebuild the cache script for one domain
/go/cache example.com

# Rebuild it for all domains
/go/cache all

Syntax

/go/cache [domain|all]

If you run it without root, it re-runs itself with sudo.


Options

Argument What it does
<domain> Rebuilds the cache script for that domain only.
all Rebuilds it for every domain.
(none) Same as all.

A domain is skipped silently when /home/<domain>/www does not exist.

Cache settings

The settings are read from the Site table in /var/lib/sqlite/site.db. Run the command again after you change them.

Setting Meaning
CacheTTL How long a cached page stays valid, in seconds. 0 turns the cache off.
CacheActive 1 turns the cache on, 0 turns it off.
CacheLength 0 means no limit. Any other value means only URLs longer than this many characters are cached, so shorter URLs (such as the home page) are never cached.
CacheExclude Extra URL parts that must never be cached, separated by |.

Output

The command prints nothing. To check the result, open the generated file:

cat /home/example.com/etc/cache.php

Each run also adds a line to /var/log/go/cache.log.


Examples

# Rebuild one domain, then all domains
/go/cache example.com
/go/cache all
# See the current cache settings of a domain
sqlite3 /var/lib/sqlite/site.db "select CacheTTL,CacheActive,CacheLength,CacheExclude from Site where Domain='example.com'"
# Change the cache time to one hour and apply it
sqlite3 /var/lib/sqlite/site.db "update Site set CacheTTL=3600 where Domain='example.com'"
/go/cache example.com
# Clear the cached pages of a domain
rm -f /var/cache/example.com/*.html

Troubleshooting

Symptom Likely cause Fix
Nothing happens for a domain /home/<domain>/www does not exist. Check the domain name and that the account exists.
Changes to the settings have no effect cache.php was not rebuilt. Run /go/cache <domain>.
Pages are not cached CacheTTL is 0, CacheActive is 0, the URL matches an excluded part, or the URL is not longer than CacheLength. Check the settings.
Pages are not cached, but the settings are right The cache folder /var/cache/<domain> is missing or not writable by the site's PHP user. Create it, and make it writable.
Old content keeps appearing Cached pages are still valid. Delete the files in /var/cache/<domain>/, or lower CacheTTL.
The site shows a blank page or a PHP error after the command A setting was empty, which creates invalid PHP (see Known issues). Set CacheActive and CacheLength to numbers, then run the command again.
A page that should not be cached is cached Its URL does not match an excluded part. Add a part of the URL to CacheExclude and run the command again.

Details

What the generated script does

For every request, the script:

  1. Stops and does nothing when CacheTTL is 0, CacheActive is 0, the URL matches an excluded part, or the URL is not longer than CacheLength.
  2. Looks for a saved copy in /var/cache/<domain>/. The file name is the MD5 hash of the full URL (scheme, host, path, and query string) plus .html. http and https versions, and different query strings, are cached separately.
  3. If the saved copy is not older than CacheTTL, sends it and stops.
  4. Otherwise lets the page run normally, and saves the result if it contains </html> or </body>.

The command only writes the script. Loading it for the site is done by the site's PHP configuration, not by this command.

Excluded URLs

These parts are always excluded: admin, /cp, login, sign, logout, forget, webmail, dashboard, and ajax. Anything you add to CacheExclude is added to this list.

A URL is excluded when it contains any of these parts, so sign also matches /design. Dots and slashes are escaped, so a dot in your list means a literal dot.

Clearing the cache

The command only writes the script. To clear a domain's cached pages, delete the .html files in /var/cache/<domain>/. To clear Cloudflare's copy, use purge.

Security

[!WARNING] The command sets the permission of cache.php to 777, so any user on the server can change a file that runs as PHP on the site. Use a stricter permission such as 644.

Known issues


See also

Command Description
purge Delete the Cloudflare edge cache (purge everything)
clean Clean and remove unnecessary files to free up space
fpm Restart all installed PHP-FPM versions on your server
gzip Enable or disable gzip compression in the web server
conf Rebuild the Apache/Nginx configuration in GoAdmio