我想使用新的缓存组件在Redis中存储数据。
我想为池配置不同的数据生存期。
现在,我配置了:
framework:
cache:
app: cache.adapter.redis
default_redis_provider: "redis://localhost:6379"
pools:
app.cache.codification:
adapter: cache.app
default_lifetime: 86400
app.cache.another_pool:
adapter: cache.app
default_lifetime: 600
Run Code Online (Sandbox Code Playgroud)
但是我不知道如何app.cache.codification在我的代码中使用池。我宣布了以下服务:
acme.cache.repository.code_list:
class: Acme\Cache\Repository\CodeList
public: false
arguments:
- "@cache.app"
- "@acme.webservice.repository.code_list"
Run Code Online (Sandbox Code Playgroud)
我这样使用它:
class CodeList
{
private $webserviceCodeList;
/**
* @var AbstractAdapter
*/
private $cacheAdapter;
public static $CACHE_KEY = 'webservices.codification.search';
private $lists;
/**
* @param AbstractAdapter $cacheAdapter
* @param WebserviceCodeList $webserviceCodeList
*/
public function __construct($cacheAdapter, $webserviceCodeList)
{
$this->cacheAdapter = $cacheAdapter;
$this->webserviceCodeList = $webserviceCodeList;
}
/**
* @param …Run Code Online (Sandbox Code Playgroud) 如果我编写一些带有弃用通知的 PHP 代码,它会显示在本地环境中。
示例:index.php
<?php
function super(string $test='', string $essai)
{
return 'toto';
}
super('sy', 1);
exit;
Run Code Online (Sandbox Code Playgroud)
显示:
Deprecated: Optional parameter $test declared before required parameter $essai is implicitly treated as a required parameter in /var/www/public/index.php on line 9
Run Code Online (Sandbox Code Playgroud)
这很好。
但是 Laravel 控制器中的完全相同的代码不会显示,并且不会存储在任何日志文件中。我将配置 app.env 设置为“local”,将 app.debug 设置为 true,将 app.log_level 设置为“debug”。知道我缺少什么吗?
我正在尝试将模型进程的一些处理拆分为多个作业。假设我要处理 300 个模型。我想启动3个作业,每个作业将处理100个模型。在每项工作中,我想按 10 个模型为一组进行延迟加载。
如果我执行以下代码:
$models = MyModel::offset(0)->limit(100)->lazy(10);
$j = 0;
foreach ($models as $model) {
$j++;
}
echo $j;
Run Code Online (Sandbox Code Playgroud)
输出是:
300
我认为只应该处理 100 个模型。
我不明白为什么我的所有模型都被处理。
如果有人知道真相...:)