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 22.214.171.124).
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 126.96.36.199 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 amount of memory used for each cache miss as the response is being received. If you have a high request rate but are low on memory, you may want to lower this value to 4 KB. Squid allocates memory for object data in 4-KB chunks. Thus, it makes sense to assign this directive a multiple of 4 KB. Other values end up wasting memory.
In-memory objects fall into one of two groups: in-transit or complete. Squid uses the memory cache for both types. Complete objects are held in memory only if there is some free space. They have lower priority than in-transit objects. If your cache is busy, the memory cache may contain nothing but in-transit objects (or, maximum_object_size_in_memory chunks of in-transit objects, actually). Furthermore, Squid always allocates memory for in-transit objects, even if it must exceed the cache_mem limit. When an in-transit object becomes a complete object, it is kept in memory only if the memory cache size is below the limit.
The memory_replacement_policy directive is analogous to replacement_policy. It controls the replacement policy for objects cached in memory. Because the memory cache is typically much smaller than the disk cache, your choice of replacement policy may have a bigger impact. See Section 7.5 for a description of available replacement policies.