2

I'm running APC mainly to cache objects and query data as user cache entries, each item it setup with a specific time relevant to the amount of time it's required in the cache, some items are 48 hours but more are 2-5 minutes.

It's my understanding that when the timeout is reached and the current time passes the created at time then the item should be automatically removed from the user cache entries?

This doesn't seem to be happening though and the items are instead staying in memory? I thought maybe the garbage collector would remove these items but it doesn't seem to have done even though it's running once an hour at the moment.

The only other thing I can think is that the default apc.user_ttl = 0 overrides the individual timeout values and sets them to never be removed even after individual timeouts?

These should have been removed?

2 Answers 2

8
+50

In general, a cache manager SHOULD keep your entries for as long as possible, and MAY delete them if/when necessary.

The Time-To-Live (TTL) mechanism exists to flag entries as "expired", but expired entries are not automatically deleted, nor should they be, because APC is configured with a fixed memory size (using apc.shm_size configuration item) and there is no advantage in deleting an entry when you don't have to. There is a blurb below in the APC documentation:

If APC is working, the Cache full count number (on the left) will display the number of times the cache has reached maximum capacity and has had to forcefully clean any entries that haven't been accessed in the last apc.ttl seconds.

I take this to mean that if the cache never "reached maximum capacity", no garbage collection will take place at all, and it is the right thing to do.

More specifically, I'm assuming you are using the apc_add/apc_store function to add your entries, this has a similar effect to the apc.user_ttl, for which the documentation explains as:

The number of seconds a cache entry is allowed to idle in a slot in case this cache entry slot is needed by another entry

Note the "in case" statement. Again I take this to mean that the cache manager does not guarantee a precise time to delete your entry, but instead try to guarantee that your entries stays valid before it is expired. In other words, the cache manager puts more effort on KEEPING the entries instead of DELETING them.

2
  • Great answer, do you know if the ttl set via apc_add/apc_store overdies the apc.user_ttl?
    – Dan
    Sep 15, 2013 at 21:49
  • 1
    I don't know for sure, I would imagine that is the case. What I generally do is to set system-wide TTL and not having to worry about individual situations. If I have memory pressure which calls for expiring items quicker, I'd prefer to just increase the overall APC size a bit, that way I save myself a lot of headaches. If your really need to fiddle with APC at this level, your caching needs might have exceed what APC can offer, and you may want to consider something like Redis.
    – stevel
    Sep 15, 2013 at 23:29
1

apc.ttl doesn't do anything unless there is insufficient allocated memory to store new coming variables, if there is sufficient memory the cache will never expire!!. so you have to specify your ttl for every variable u store using apc_store() or apc_add() to force apc to regenerate it after end of specified ttl passed to the function. if u use opcode caching it will also never expire unless the page is modified(when stat=1) or there is no memory. so apc.user_ttl or apc.ttl are actually have nothing to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.