RAM Cache and Redirecting to it in Apache

I’ve just had to cache all images on a site in RAM in order to limit the amount of disc scratching going on.

Mounting an existing folder can be done like this:

mount -t tmpfs -o size=3G,mode=0777 tmpfs /var/www/domain.com/cache

Add remount, in front of size in that line to remount.

After that I copied some folder images into the cache folder.

It might be tempting to then try some rewrite magic in the .htaccess file (as it was for me) but as I learned more I realized that the action needs to come earlier, in the virtual hosts file in fact:

AliasMatch /images/(.*)$ /var/www/domain.com/cache/images/$1

Above is an example of a line I put in my virtual hosts file for the domain in question. It will load the images from the cache folder instead of the normal folder.

Seems to be working.

Related Posts

Tags: , ,