Appendix B. The Memory Cache

Squid stores some of its recently retrieved objects fully in memory. As you might expect, serving objects from memory is generally faster than reading the data from the disk. In some places, Squid calls this the hot object cache. The cache_mem directive specifies how much memory Squid should use for in-memory objects.

I usually recommend setting cache_mem to a small size, such as something between 8 and 32 MB. If you happen to have tons of extra memory, you can set it higher. In most cases, however, your extra memory is better used by increasing your disk cache size (see Section 7.1.3.2).

Many people misunderstand the cache_mem directive. They expect it to limit the total amount of memory that Squid uses. Unfortunately, for them, this assumption is incorrect. Squid doesn’t have a directive that limits total memory consumption. See Section 7.1.3.2 and Section 16.1.8.

The current version of Squid (2.5) stores objects in memory only if they come from the network (origin server or neighbor cache). If Squid reads an object from disk, it doesn’t also store it in memory. Older versions of Squid had that functionality. However, it was removed during a major rewrite to simplify the source code.

Only objects smaller than a certain size are held in memory. The maximum_object_size_in_memory directive controls this setting. Its default value is 8 KB, which is typically large enough to fit more than half of all responses Squid receives. This directive also limits the ...

Get Squid: The Definitive Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.