I have enabled the mod\_cache and mod\_disk\_cache Apache modules, to enable caching of dynamically generated images form a PHP script (based on width and height parameters).

Everything works fine (Apache caches the files) whenever I supply small width and height parameters to my PHP script. However when I supply larger parameters, and as the image size gets bigger (above around 50k) Apache is not caching the response anymore. In that case Apache does create a directory in the /var/cache/apache/mod\_disk\_cache but the directory is empty (it does not contain the .header and .data files).

I have tried to set the CacheMaxFileSize directive but it did not seem to work (I tried setting it a a large value (2000000) in the disk\_cache.conf file but it did not seem to have any effect and setting the directive in the site configuration file disabled all caching - caching of small files stopped working).

Has anybody encountered something similar and knows how to solve it?

Server is running Ubuntu 12.04 with Apache 2.2.22

Here is my config:

**/etc/apache2/mods-available/disk\_cache.conf**

```
<IfModule mod_disk_cache.c>
# cache cleaning is done by htcacheclean, which can be configured in
# /etc/default/apache2
#
# For further information, see the comments in that file, 
# /usr/share/doc/apache2.2-common/README.Debian, and the htcacheclean(8)
# man page.

    # This path must be the same as the one in /etc/default/apache2

    CacheRoot /var/cache/apache2/mod_disk_cache

    # This will also cache local documents. It usually makes more sense to
    # put this into the configuration for just one virtual host.

    CacheDirLevels 2
    CacheDirLength 1
    CacheIgnoreCacheControl On
    CacheIgnoreURLSessionIdentifiers jsessionid
    CacheIgnoreURLSessionIdentifiers PHPSESSID
    CacheIgnoreHeaders Set-Cookie
    CacheMaxFileSize 2000000

</IfModule>

```

**/etc/apache2/sites-available/img.mydomain.com**

```
<VirtualHost *:80>
    ServerName img.mydomain.com 
    ServerAlias img.mydomain.eu
    DocumentRoot /var/www/mydomain.com/img/

    <Directory />
        Options None
        AllowOverride None
        Order allow,deny
        Deny from all
    </Directory>

    <Directory /var/www/mydomain.com/>
        AllowOverride All
    </Directory>

    <Directory /var/www/mydomain.com/img/>
        Options FollowSymlinks
        Order allow,deny
        Allow from all
    </Directory>

    <IfModule mod_disk_cache.c>
        CacheEnable disk /cached/
    </IfModule>

    ErrorLog ${APACHE_LOG_DIR}/img.mydomain.com-error.log
    LogLevel debug
    CustomLog ${APACHE_LOG_DIR}/img.mydomain.com-access.log combined
</VirtualHost>

```

**PHP image generation script /var/www/mydomain.com/img/cached/logo.php**

```
<?php

//Generate Imagick image based on provided width and height

header("Content-Type: image/" . strtolower($image->getImageFormat()));
header("Content-Length: " . strlen($image));
header("Cache-Control: public, must-revalidate, max-age=2592000");
echo $image;

?>

```