filecache
Introduction
This module allows Drupal cache bins to be stored in the filesystem.
Use cases
File Cache can be useful in several real-world scenarios:
- Long-term caching of expensive data processing results
Keep costly computed data on disk as a permanent cache which can survive regular cache clears. - Test fixtures for data coming from external APIs
When testing code that interacts with public APIs you can cache the responses from the external services and commit them in the repository. This will make sure tests run reliable and fast since they will not be dependent on network availability. - High-speed local caching with RAM-backed storage
Write cache bins to a local ramdisk (tmpfs) for very fast read/write performance during development. Can even be useful in production environments as an alternative to a traditional memory cache like Redis or Memcached. - Shared caching across multiple applications - You can make Drupal data available to other applications by storing it on shared storage (for example a network drive) and using a standard serialization format like JSON or YAML.
- Easier debugging of cache behavior
Inspect cache files directly on disk to see what is written, when entries are created, and how cache data evolves over time. - Precomputed cache data shipped with deployments
Generate expensive cache data ahead of time, store it in files, and include those files in the production release so the data is instantly available after deployment.
Related Modules
Redis, Memcache, and MongoDB are the closest caching modules. They are usually used when the website is load balanced and there are multiple servers that use single redis/memcache instance. If you don't use multiple webservers, most likely File Cache will be faster. Also, File Cache works in shared hosting webservers.
Apc and Opcache store cache bins in PHP shared memory. This makes them very fast but the space is limited and usually they are used only for cache and cache_bootstrap cache bins.
Boost generates caches of pages that are directly served by web
server. This is much faster than any solution that uses Drupal page caching system but it's also complex to setup and limited to anonymous pages.
Authcache can cach pages for anonymous and also logged-in authenticated users. Similarly to Boost, it is very fast and also complex to configure. In contrast with Boost though, it uses cache_page cache bin and so it can work with File Cache.
Relation with cacherouter and fastpath_fscache modules for Drupal 6.
Quick Start Installation
Install and enable filecache module as usual. Add the following to site's
settings.php or settings.local.php to set the file cache backend as the default backend:
$settings['cache']['default'] = 'cache.backend.file_system';
Most likely you don't want to store the entire Drupal cache on the filesystem but only specific cache bins. For example you can put the page cache in file storage, but keep using the database backend for all other bins:
$settings['cache']['bins']['page'] = 'cache.backend.file_system';
Next, configure the default location of the cache folder. For security reasons this folder should be outside the webroot. Since the caches might contain sensitive data, this folder should never be exposed on the internet. In this example the cache folder will be located in the path /var/cache/myproject/filecache. Please ensure that this folder is writable by the webserver by configuring the relevant ownership and permissions. Add the following to settings.php or settings.local.php:
# Define the default cache folder.
$settings['filecache']['directory']['default'] = '/var/cache/myproject/filecache';
# Store the entity cache in the private files folder by using the stream wrapper.
$settings['filecache']['directory']['bins']['entity'] = 'private://filecache/entity';
# Store the page cache in a shared network drive so it can be used by multiple Drupal instances.
$settings['filecache']['directory']['bins']['page'] = '/mnt/share/filecache/page';
# Store the container cache in a fast local memory drive.
$settings['filecache']['directory']['bins']['container'] = '/mnt/ramdisk/filecache/container';
Go to Status report page admin/reports/status. Confirm that there
are no errors related to the File Cache module.
Please read README.txt for further information.