【问题标题】:ApcCache symfony2 create cache from cliApcCache symfony2 从 cli 创建缓存
【发布时间】:2015-09-07 06:34:04
【问题描述】:

我在 symfony 中有控制台命令。此命令必须重新计算一些报告,并将此报告保存到缓存中。 (命令必须每 30 分钟在 cron 中运行一次) 其次,当用户在网站上查看报告时,一定不要等待生成报告。

当我重新计算并根据浏览器请求设置缓存时,它可以工作(如果缓存不存在,则重新计算和 ganarete 缓存)。 从控制台命令重新计算和设置缓存不起作用。我没有收到任何错误,但缓存没有保存。

这是我在 symfony 中的测试命令:

<?php

namespace Test\ReportsBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;


class RefreshSalesTxtReportCacheCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this
                ->setName('crm:report:refreshSalesTxtCache')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {     
        $this->cache = new \Doctrine\Common\Cache\ApcCache();
        $this->cache->delete('test');
        $this->cache->save('test', 'content', 9999999999);
        echo phpinfo();
        var_dump($this->cache->fetch('trol'));

        die();
    }

}

当我运行这个命令时:

php app/console crm:report:refreshSalesTxtCache -e prod |grep apc

我得到输出:

/etc/php5/cli/conf.d/20-apcu.ini,
apc
apcu
apc.coredump_unmap => Off => Off
apc.enable_cli => On => On
apc.enabled => On => On
apc.entries_hint => 4096 => 4096
apc.gc_ttl => 3600 => 3600
apc.mmap_file_mask => no value => no value
apc.preload_path => no value => no value
apc.rfc1867 => Off => Off
apc.rfc1867_freq => 0 => 0
apc.rfc1867_name => APC_UPLOAD_PROGRESS => APC_UPLOAD_PROGRESS
apc.rfc1867_prefix => upload_ => upload_
apc.rfc1867_ttl => 3600 => 3600
apc.serializer => php => php
apc.shm_segments => 1 => 1
apc.shm_size => 32M => 32M
apc.slam_defense => On => On
apc.smart => 0 => 0
apc.ttl => 0 => 0
apc.use_request_time => On => On
apc.writable => /tmp => /tmp

【问题讨论】:

    标签: php symfony caching command-line-interface apc


    【解决方案1】:

    您还有其他使用 memcache 容器的选项,如下所示:

    第一次运行脚本时添加到缓存中 检查缓存是否报告 id 被设置到缓存中:

     $key = 'reportCache_'.$reportId;
     $content = $this->getContainer()->get('service.memcache')->get($key);
     if ($content === false) {
        $this->getContainer()->get('service.memcache')->setAlways($key, $reportContaint, 3600*12);
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-21
      • 2011-09-20
      • 2014-10-06
      • 2016-05-07
      • 1970-01-01
      • 2011-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多