- What is Caching?
- What is Varnish?
- Why is Varnish required for Drupal site?
- Can I control Caching?
- Can I control Varnish Caching?
- Can I switch off Caching?
- Are files stored in Database?
- Are files cached?
Drupal is a content management system which stores all the content and most of the configurations in a database. When someone visits a page of a website running in Drupal content management system, Drupal makes a query to the database and generates the page on the fly. Most of these queries require accessing multiple tables in the database. As you can imagine, when the traffic is more, there will be many requests to the database and can potentially slow down the website's response or make it unresponsive in some cases. To avoid this overload on database, Drupal provides a mechanism to cache these pages. Drupal generates the pages once and stores them in a different easy to access to tables. This cached version is then served to future queries for a period of time. We can configure the duration these pages can serve an older cache before needing to re-cache.
Varnish is a reverse proxy server that provides a caching service on top of any website. Varnish servers stores a copy of webpages for a pre-defined duration. Being an external server, Varnish can only cache those pages that are visible to public. When someone tries to access your website, they are first sent to the Varnish server which then either serves the previously stored copy of that page or creates a new copy depending on if the pre-defined duration for the stored copy has expired or not.
Although Drupal provides its own caching system, as explained above, the cached versions are still stored in the same database within the same infrastructure. If the database is experiencing issues then Drupal's cache is subjected to those issues as well. Varnish on the other hand is external to the Drupal infrastructure. It will store the cached versions outside the Drupal environment and serve those pages from there. Varnish works only if Drupal caching is enabled.
Yes, if you are full admin to your Drupal site, these settings are available under Configuration --> Development --> Performance.
A good explanation of the settings on this page is at https://pantheon.io/docs/articles/drupal/drupal-performance-and-caching-...
Yes, Varnish works based on the Drupal caching settings explained in the above question.
Yes, though we strongly recommend against it.
The PDFs, document, image and other files linked in the Drupal websites are not stored in the database. These are served directly by the web server.
Drupal's caching system does not cache files because the files are served directly by the web server. Varnish caching system caches the publicly visible files for the duration defined in the Drupal's cache settings. Most web browsers cache files locally on the end-users systems as well. This cannot be controlled on the Drupal level.