我正在使用CakePHP(版本1.3.8)和APC(版本3.1.3p1)进行以下设置:
apc.ini
extension=apc.so
apc.enabled=1
apc.enable_cli=0
apc.shm_size=128
apc.stat=0
apc.num_files_hint=10000
apc.user_entries_hint=10000
apc.max_file_size=5
apc.user_ttl = 3600
apc.ttl = 3600
Run Code Online (Sandbox Code Playgroud)
蛋糕核心设置:
Cache::config('default', array(
'engine' => 'Apc',
'duration'=> '+5 minutes',
'probability'=> 100,
'prefix' => Inflector::slug(APP_DIR) . '_',
));
Run Code Online (Sandbox Code Playgroud)
由于某种原因,为用户缓存条目列出的超时(通过mysite.com/apc.php查看)都是86313600秒(999天).考虑到我在apc.ini中设置apc.user_ttl和apc.ttl并通过Cake设置持续时间,我不知道为什么会这么高.我已经尝试清除所有APC缓存并重新启动Apache.
任何援助将不胜感激.谢谢.
编辑:认为值得一提的是,通过apc.php显示的运行时设置确实根据apc.ini配置设置了正确的TTL:
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: 3600
apc.include_once_override: 0
apc.lazy_classes: 0
apc.lazy_functions: 0
apc.max_file_size: 5
apc.mmap_file_mask
apc.num_files_hint: 10000
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.shm_segments: 1
apc.shm_size: 128
apc.stat: 0
apc.stat_ctime: 0
apc.ttl: 3600
apc.use_request_time: 1
apc.user_entries_hint: 10000
apc.user_ttl: 3600
apc.write_lock: 1
Run Code Online (Sandbox Code Playgroud)
我已经解决了这个问题,最终导致我认为“默认”值应该是什么和 CakePHP 认为“默认”值应该是什么之间的混淆。
在 cake/libs/cache.php 中,有一个 write 函数,它设置缓存条目的键、值和持续时间,并将其传递给适当引擎的 write 函数(在本例中为 APC)。在此函数中,它会检查 core.php 中的缓存配置设置,以查看您是否在那里指定了持续时间。core.php 中的代码:
Cache::config('default', array(
'engine' => 'Apc',
'duration'=> 9000,
'probability'=> 100,
'prefix' => Inflector::slug(APP_DIR) . '_',
));
Run Code Online (Sandbox Code Playgroud)
您可以看到第一个参数是字符串“default”,我认为这意味着所有 APC 缓存的默认值应使用以下数组,其中包括 9000 秒的持续时间。但是,在上述写入函数中,它会检查实例的 __name 变量,在缓存条目的情况下,该变量设置为“_cake_core_”,而不是默认字符串值“default”。不久之后,它会进入配置设置并查找“_cake_core_”值。因为这不应该被发现(因为我没有明确设置它),或者如果 Cake 设置了一些值,它会被我的默认值(根据我的默认定义)覆盖,它将依赖于我已经设置的值设置如上。然而,事实并非如此。在cake/libs/configure.php的__loadBoostrap函数中:
if (Configure::read() >= 1) {
$duration = '+10 seconds';
} else {
$duration = '+999 days';
}
if (Cache::config('_cake_core_') === false) {
Cache::config('_cake_core_', array_merge((array)$cache['settings'], array(
'prefix' => $prefix . 'cake_core_', 'path' => $path . DS . 'persistent' . DS,
'serialize' => true, 'duration' => $duration
)));
}
Run Code Online (Sandbox Code Playgroud)
因此,如果 debug 设置为 0(这是当没有传递任何内容时,Configure::read() 返回的结果)并且配置字符串是“_cake_core_”(就像我的缓存条目一样),它将 $duration 设置为“+999”天',而不是我传递的值。解决方案是在 core.php 中创建另外几行,如下所示:
Cache::config('_cake_core_', array(
'engine' => 'Apc',
'duration'=> 9000,
'probability'=> 100,
'prefix' => Inflector::slug(APP_DIR) . '_',
));
Run Code Online (Sandbox Code Playgroud)
它会覆盖 Cake 的“默认”或硬编码值 10 秒或 999 天,具体取决于调试值。
| 归档时间: |
|
| 查看次数: |
1169 次 |
| 最近记录: |