Squid_ The Definitive Guide - Duane Wessels [58]
Options
Squid has two scheme-independent cache_dir options: a read-only flag and a max-size value.
read-only
The read-only option instructs Squid to continue reading from the cache_dir, but to stop storing new objects there. It looks like this in squid.conf:
cache_dir ufs /cache0 7000 16 256 read-only
You might use this option if you want to migrate your cache storage from one disk to another. If you simply add one cache_dir and remove another, Squid's hit ratio decreases sharply. You can still get cache hits from the old location when it is read-only. After some time, you can remove the read-only cache directory from the configuration.
max-size
With this option, you can specify the maximum object size to be stored in the cache directory. For example:
cache_dir ufs /cache0 7000 16 256 max-size=1048576
Note that the value is in bytes. In most situations, you shouldn't need to add this option. If you do, try to put the cache_dir lines in order of increasing max-size.
Disk Space Watermarks
The cache_swap_low and cache_swap_high directives control the replacement of objects stored on disk. Their values are a percentage of the maximum cache size, which comes from the sum of all cache_dir sizes. For example:
cache_swap_low 90
cache_swap_high 95
As long as the total disk usage is below cache_swap_low, Squid doesn't remove cached objects. As the cache size increases, Squid becomes more aggressive about removing objects. Under steady-state conditions, you should find that disk usage stays relatively close to the cache_swap_low value. You can see the current disk usage by requesting the storedir page from the cache manager (see Section 14.2.1.39).
Note that changing cache_swap_high probably won't have a big impact on Squid's disk usage. In earlier versions of Squid, this parameter played a more important role; now, however, it doesn't.
Object Size Limits
You can control both the maximum and minimum size of cached objects. Responses larger than maximum_object_size aren't stored on disk. They are still proxied, however. The logic behind this directive is that you don't want a really big response to take up space better utilized by many small responses. The syntax is as follows:
maximum_object_size size-specification
Here are some examples:
maximum_object_size 100 KB
maximum_object_size 1 MB
maximum_object_size 12382 bytes
maximum_object_size 2 GB
Squid checks the response size in two different ways. If the reply includes a Content-Length header, Squid compares its value to the maximum_object_size value. If the content length is the larger of the two numbers, the object becomes immediately uncachable and never consumes any disk space.
Unfortunately, not every response has a Content-Length header. In this case, Squid writes the response to disk as data comes in from the origin server. Squid checks the object size again only when the response is complete. Thus, if the object's size reaches the maximum_object_size limit, it continues consuming disk space. Squid increments the total cache size only when it is done reading a response.
In other words, the active, or in-transit, objects don't contribute to the cache size value Squid maintains internally. This is good because it means Squid won't remove other objects in the cache, unless the object remains cachable and then contributes to the total cache size. However, it is also bad because Squid may run out of free disk space if the reply is very large. To reduce the chance of this happening, you should also use the reply_body_max_size directive. A response that reaches the reply_body_max_size limit is cut off immediately.
Squid also has a minimum_object_size directive. It allows you to place a lower limit on the size of cached objects. Responses smaller than this size aren't stored on disk or in memory. Note that this size is compared to the response's content length (i.e., the size of the reply body), which excludes the HTTP headers.
Allocating Objects to Cache Directories
When Squid wants to store a cachable response