tags:

views:

681

answers:

2

What happen when you try to add a variable into APC and the APC cache is full? Does it automatically remove least used variable from the cache?

Thanks.

+3  A: 

According to APC: Runtime Configuration, "In the event of a cache running out of available memory, the cache will be completely expunged if ttl is equal to 0. Otherwise, if the ttl is greater than 0, APC will attempt to remove expired entries."

So if there is a non-zero TTL, it will remove entries whose time to live has passed. ;) Otherwise, it will remove the entire cache.

I notice this doesn't really address what happens if the cache runs out of memory and you have an excessively high TTL.

Matthew Flaschen
A: 

From experience (we run it in production), if you do not set a TTL or the TTL is very very high and nothing is out of date, the entire cache is flushed (as in made empty). You really want to try and avoid this as it will cause a load spike on the next request that PHP has to deal with, becuase for every file needed APC will need to compile it and store it in memory (which as a slightly slower process than not having a cache enabled at all). Also if you are recieving lots of traffic and empty cache, you will experience cache slam (see google for the evilness of this)

As a side note, see this old presentation for a fairly rough guide to APC and things to watch out for http://t3.dotgnu.info/slides/oscon07.pdf Somethings maybe out of date in it but the theory still holds true.

James Butler