Magento 1.4.2 + APC:清除缓存对更改设置没有影响

时间:2012-04-13 13:02:21

标签: magento apc

我们有一台Magento 1.4.2 CE服务器,安装了APC 3.1.9,Magento配置为使用它作为后端缓存。

我们遇到了一种奇怪的缓存行为。我们在后端进行的每个更改都不会显示,直到apache2重新启动/ APC操作码缓存已被清除。这包括例如更改欢迎消息或激活/停用Google Analytics。

问题:为什么APC缓存整页?我们不希望这种行为,似乎不是标准的。对于后端的每一个小变化,我们都需要清除操作码缓存。清除Magento缓存无济于事。

为了完整性,这是我们的/etc/php5/conf.d/apc.ini

extension=/usr/lib/php5/20090626/apc.so
apc.enabled=1
apc.file_update_protection=2
apc.optimization=0
apc.shm_size=128M
apc.include_once_override=0
apc.shm_segments=1
apc.gc_ttl=7200
apc.ttl=7200
apc.num_files_hint=1024
apc.enable_cli=0

在7200s TTL之后,启用/禁用Google Analytics也不起作用。也许是因为我们的缓存此时没有运行。使用其容量的40%,命中率约为98%。

这是apc.php的完整设置输出:

apc.cache_by_default    1
apc.canonicalize        1
apc.coredump_unmap      0
apc.enable_cli      0
apc.enabled         1
apc.file_md5        0
apc.file_update_protection  2
apc.filters 
apc.gc_ttl          7200
apc.include_once_override   0
apc.lazy_classes        0
apc.lazy_functions      0
apc.max_file_size       1M
apc.mmap_file_mask  
apc.num_files_hint      1024
apc.preload_path    
apc.report_autofilter   0
apc.rfc1867         0
apc.rfc1867_freq        0
apc.rfc1867_name        APC_UPLOAD_PROGRESS
apc.rfc1867_prefix      upload_
apc.rfc1867_ttl     3600
apc.serializer      default
apc.shm_segments        1
apc.shm_size        128M
apc.slam_defense        1
apc.stat            1
apc.stat_ctime      0
apc.ttl         7200
apc.use_request_time    1
apc.user_entries_hint   4096
apc.user_ttl        0
apc.write_lock      1

2 个答案:

答案 0 :(得分:1)

APC保留终端和基于Web的缓存。因为你只能清除" web"来自基于Web的URL调用而非命令行的缓存命中,这就是重启apache后清除基于APC Web的缓存的原因。您很可能希望设置脚本以使用类似的脚本清除缓存,以便您可以从CLI或脚本中调用它。

echo "Clearing APC web cache\n";
system('wget --spider --quiet http://localhost/clear_apc_cache.php');

echo "Clearing APC command line user cache\n";
apc_clear_cache('user');

echo "Clearing APC command line opcode cache\n";
apc_clear_cache();

显然,您需要使用相同的两个APC内部方法调用创建clear_apc_cache.php相应文件,apc_clear_cache();apc_clear_cache('user');

此外,我还设置了一个本地区域来查看APC缓存:

http://www.electrictoolbox.com/apc-php-cache-information/

答案 1 :(得分:0)

您也可以将apc.stat设置为零。 PHP.ini文件中的(apc.stat = 0)。

如果设置为1,则不会查找文件更新,这会提供更好的性能,但需要在更新后重新启动apache。设置为0将检查文件更新并将其添加到缓存中(即,您的更新将在网站上显示)。