This module provides a cache backend which leverages gzip compression for the
stored data.
Upon cache set the cache data will be gzipped, if the gzipped data is smaller
than the original data the compressed data will be stored in the cache bin.
This Database Backend adds two additional states to serialized column of Drupal
cores DatabaseBackend.
- SERIALIZED_COMPRESSED (2): a serialized object, compressed.
- STRING_SERIALIZED_COMPRESSED (3): a compressed string.
Benchmark
100k+ nodes, same time needed for generation as with the default database backend. Storage comparison:
bin | default database backend (total size in MB) | compressed cache database backend (total size in MB) | reduction in % |
---|---|---|---|
cache_data | 4385,48 | 532,48 | 87,85811359 |
cache_dynamic_page_cache | 12419,56 | 4486,42 | 63,87617597 |
cache_page | 20641,09 | 5701,08 | 72,37994699 |
cache_render | 7026,89 | 3110,8 | 55,73005981 |
Please add your findings to Benchmarks, comparison
Requirements
php functions: gzcompress, gzuncompress come with zlib extension.
Installation
download and install the module as ususal.
Swap the existing database backend with our compressed one in settings.php:
// Default cache bin
$settings['cache']['default'] = 'cache.backend.database_compressed_cache';
// Specific cache bins
$settings['cache']['bins']['data'] = 'cache.backend.database_compressed_cache';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.database_compressed_cache';
$settings['cache']['bins']['render'] = 'cache.backend.database_compressed_cache';
$settings['cache']['bins']['page'] = 'cache.backend.database_compressed_cache';
Advanced settings
/**
* Compression level
* default = 6
* @see http://php.net/gzcompress
*/
$settings['compressed_cache']['cache_compression_ratio'] = 1;
/**
* Minimum string length to add compression.
* Seems to be completely based on gut feeling. can not find any sources googling this topic.
*/
$settings['compressed_cache']['cache_compression_size_threshold'] = 100;
/**
* Whether garbage collection is enabled or not. Defaults to TRUE.
*/
$settings['compressed_cache']['garbage_collection_enabled'] = TRUE;
Related issues
Project information
- Minimally maintained
Maintainers monitor issues, but fast responses are not guaranteed. - Module categories: Performance
- 365 sites report using this module
- Created by Andre-B on , updated
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.
Releases
Development version: 8.x-1.x-dev updated 11 Sep 2023 at 11:08 UTC