Increasing squid cache directory size

→ Are you a new visitor? Please visit the page guidance for new visitors ←

Increasing squid cache directory size

The past weeks I had to set a reverse proxy using squid. For those who don’t know, squid is a web proxy, but can be used as a reverse proxy and web accelerator.

So in my cases I used squid as both a reverse proxy and web accelerator. In this article however I’m going to explain an easy way to increase or create a cache directory for squid.

This is rather useful for caching web files on disk rather then always query the web server. The default installation of squid from yum or apt should have the cache directory size up to 100MB.

To increase the cache directory size, simply edit the file /etc/squid/squid.conf and locate the directive:

By default, the cache_dir directory may be commented.

  • /var/spool/squid – This is the directory folder where squid will use to swap cache your server web files
  • 100 – The amount of disk space to use in MB for your caching directory
  • 16 – the first-level subdirectories which will be created in your cache directory
  • 256 – The number of second-level subdirectories which will be created under each first level directory

Next you need to consider how much disk space you wish to allow for caching, for example, lets say we wish to allocate 3GB of space to squid cache. We would use the following directive:

This will allocate 3GB of disk space to your squid cache directory. Save the file and exit.

Then make sure squid is fully stopped:

Run the following command to recreate the Squid Cache Directory:

Then start the service again:

That’s all! Enjoy your new Squid configuration!

  • Wastrel Way

    This is helpful, clear and concise. However, editing the /etc/squid/squid.conf file is really a pain, since it is 7000+ lines long. I do not know why everyone says “simply edit” that file.

    I think it’s easier to create two new files: /etc/squid/squid.conf.forward and /etc/squid/squid.conf.reverse. Then use the “include” directive, at line 29 (or around there) in /etc/squid/squid.conf like this:

    include /etc/squid/squid.conf.forward
    include /etc/squid/squid.conf.reverse

    That way, you do not have to edit the default squid.conf file, except to add the includes, and your changes are in smaller files and they are easier to modify as needed. It’s a lot easier to know what you are doing.

    Is there a way to specify how long something remains in the cache?

    • I like your thinking 🙂

      Haven’t used squid in quite some time, from what I recall, it honors the backend expire / last modified header, this is of course when using it as a reverse proxy. I’ve used it before for this, now I’m using nginx due to the option to terminate ssl at frontend, rather than the backend and its faster.

      But if you use it as a normal http proxy cache for, say in a company where you control your ACL for your company staff, than I’m not sure that would work, although you can still send from browser a request to receive fresh content, and that would work (ctrl+f5?)

      However did a quick google search on this, looks like with the newest version of squid, I found is what you’re looking for. You can specify there a refresh pattern for each file extensions you need and the expire / last modification there.

      Check here:

      Has a nice description of the said option in squid!

Request an article ←