且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

APC值随机消失

更新时间:2023-12-05 10:35:52

我将尝试根据所学知识回答自己的问题.

I will try to answer my own question from what I've learned.

首先,就像许多人正确指出的那样.

Firstly like many people has rightly pointed out.

APC is not persistent.

对于我来说,在没有实际解释甚至更好地指导如何使用它的情况下,我很难接受这一说法.

It was for me hard to accept this statement without a practical explanation or even better a guide on how to work with it.

我发现有些规则或陷阱值得我们注意-许多仍然使我难以理解.使用APC API意味着同时使用apc_fetchapc_store都可能失败,或者更准确地说,是未命中.以及为什么当您期望数据是神秘之处时有时会收到NULL的原因.

I've come to find that there are some rules or rather pitfalls to be aware of - many still eludes me. Using the APC API means using apc_fetch and apc_store both of these can fail, or as it is more correctly put, miss. And why you sometimes receive NULL when you expected data is where the mystery lies.

以下是一些随机的信息:

Here are some random bits of information:

  • 如果您尝试在TTL用尽之前存储值,则会创建一个新条目.因此,请减慢写入速度或降低TTL.

高速缓存条目的秒数 允许在插槽中闲置以防这种情况 另一个需要缓存入口插槽 入口.将此保持为零意味着 APC的缓存可能会填满 使用陈旧条目,而使用较新条目 将不会被缓存. -- http://php.net/manual/en/apc.configuration.php

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. Leaving this at zero means that APC's cache could potentially fill up with stale entries while newer entries won't be cached. - http://php.net/manual/en/apc.configuration.php

  • 试玩apc.ttlapc.user_ttl,直到找到适合自己的内容-直到看到很多匹配,而不是很多条目为止.

    • Play around with apc.ttl and apc.user_ttl till you find something that suits you - until you see lots of hits and not to many entries.

      apc_fetchapc_store可以返回NULL,例如上面提到的一些原因,例如ttl另一个原因可能是密钥获取超时.但是重点是围绕它的设计.期待这个.

      apc_fetch and apc_store can return NULL for a number of reasons, some hinted above, such as ttl another reason can be a key fetch timeout. But the point is design-around it. Expect this.

      如果您像我一样对APC的行为感到非常沮丧,请查看由scoates向我指出的这篇文章:

      If you like me have been feeling very frustated about APC's behaviour have a look at this article pointed out to me by scoates: http://phpadvent.org/2010/share-and-enjoy-by-gopal-vijayaraghavan . It will not give you much answers but some basic knowledge about cache design and perhaps like me some relief in the fact I'm not alone :)

      对于我在问题中描述的类路径问题,我决定使用局部变量来构建缓存,然后最后通过一次apc_store调用将其存储在缓存中.这使命中率上升,每个键的缓存条目下降,而我的代码现在运行得很快.

      In my case with the class-path issue described in my question, I decided to use a local variable to build up the cache and then at the end storing it in the cache with one single apc_store invocation. This brought the hits way up and the cache entries per key way down - and my code is now running fast.