How Caching Works
ServerPilot only enables caching that is safe for all applications. The caching enabled by ServerPilot will never cause your site visitors to see stale content.
Your applications may use additional caching of their own if they were designed for it.
How Browser Caching Works
ServerPilot allows browsers to ask if a file has changed since the last time the browser requested it, ensuring the browser never uses stale cached content.
Never stale cache: Last-Modified and If-Modified-Since Headers
When a browser requests a file, the server includes additional information about the file in the response headers it sends back with the file. This includes a response header called Last-Modified that tells the browser the date and time the file was last changed.
When a browser receives a file from the server, it remembers the Last-Modified date of the file. The next time the browser requests the same file from the server, it includes the date the file was last modified in a request header called If-Modified-Since. The server then checks whether the requested file has changed since that time. If the file has not changed, the server responds with 304 Not Modified to tell the browser it should continue using the same file it already has. If instead the file has changed, the server will send back the newer file's contents along with the its new modification date in the Last-Modified header.
Browsers can always safely use the Last-Modified header, so ServerPilot includes this header in all responses to requests for static files. Your PHP application may also include Last-Modified headers in its responses and check for If-Modified-Since headers in requests.
Sometimes stale cache: Expires and Cache-Control: max-age Headers
It's also possible to tell browsers to cache a response for a period of time and to reuse that cached file without checking if the file has changed on the server. This is done with the Expires or Cache-Control: max-age headers.
How PHP Response Caching Works
ServerPilot does not enable any caching of PHP-generated responses.
The slowest part of most web application is the time it takes for PHP to dynamically generate the response to any given request. This includes time PHP may spend communicating with a database, communicating with third-party APIs, and rendering output.
However, caching PHP responses can be very risky. There are many application-specific issues to consider, such as whether private or user-specific content is cached. If you are interested in caching responses generated by PHP, see your application's caching documentation for how to safely enable caching within the application.
How PHP Opcode Caching Works
ServerPilot enables the PHP opcode cache and configures it so that it is never stale.
All versions of PHP, starting with PHP 5.5, include a low-level form of caching called opcode caching (also known as the Opcache). This form of caching speeds up PHP requests by allowing the PHP interpreter to avoid needing to repeatedly parse and compile each script every time it is used.
ServerPilot configures PHP so that PHP will never use an old version of a file from the opcode cache. Whenever a file is modified, that file's cached opcodes will be cleared and new opcodes generated and cached the next time the file is used.
How Memory Caching Works
Your server automatically places some files and resources into memory to speed things up, because files stored in RAM can be accessed orders of magnitude more quickly than files stored on the hard drive. If that memory is needed by processes, then it is instantly freed.
If you see a lot of memory use on your server, you should not worry as long as a large portion of it is for cached/buffered files.
Last updated: August 30, 2017