Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Compressed Database Cache Backend

Security covered Under active development 102 sites

This module provides a cache backend that compresses cache data using gzip before storing it in the database. This can significantly reduce storage space with minimal impact on performance.

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

Drupal 8–10 · not 11

Ask your assistant about Compressed Database Cache Backend

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Sep 2023
Latest release
3 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core PHP Release date
8.x-1.2 Stable 8–10 Sep 11, 2023