1

Performance Symfonyの本には、一部のクラスが移動したときにAPCキャッシュをフラッシュする必要があると記載されており、これは実際に必要です。

ただし、オートローダーのAPCキャッシュをクリアする方法がわかりません。PHP関数を試してみましたapc_clear_cache()が、役に立ちませんでした。

このAPCキャッシュをクリアする方法は?

4

2 に答える 2

5

Mauro が述べたように、 apc_clear_cache は、さまざまなタイプの apc キャッシュをクリアする引数を取ることもできます。

  apc_clear_cache();
  apc_clear_cache('user');
  apc_clear_cache('opcode');

SO に関するこの関連記事も参照してください。

また、Symfony の apc:clear コマンドを追加するApcBundleもあります。

于 2013-03-04T08:03:20.550 に答える
2

以下のように、単純なコントローラー ApcController を 1 つ作成するだけです。

<?php

namespace Rm\DemoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use JMS\SecurityExtraBundle\Annotation\Secure;

/**
 * apc cache clear controller
 */
class ApcController extends Controller
{

    /**
     * clear action
     *
     * @Route("/cc", name="rm_demo_apc_cache_clear")
     *
     * @Secure(roles="ROLE_SUPER_ADMIN, ROLE_ADMIN")
     *
     * @param \Symfony\Component\HttpFoundation\Request $request
     */
    public function cacheClearAction(Request $request)
    {

        $message = "";

        if (function_exists('apc_clear_cache') 
                && version_compare(PHP_VERSION, '5.5.0', '>=') 
                && apc_clear_cache()) {

            $message .= ' User Cache: success';

        } elseif (function_exists('apc_clear_cache') 
                && version_compare(PHP_VERSION, '5.5.0', '<') 
                && apc_clear_cache('user')) {

            $message .= ' User Cache: success';

        } else {

            $success = false;
            $message .= ' User Cache: failure';

        }

        if (function_exists('opcache_reset') && opcache_reset()) {

            $message .= ' Opcode Cache: success';

        } elseif (function_exists('apc_clear_cache') 
                && version_compare(PHP_VERSION, '5.5.0', '<') 
                && apc_clear_cache('opcode')) {

            $message .= ' Opcode Cache: success';

        } else {
            $success = false;
            $message .= ' Opcode Cache: failure';
        }

        $this->get('session')->getFlashBag()
                            ->add('success', $message);

        // redirect
        $url = $this->container
                ->get('router')
                ->generate('sonata_admin_dashboard');

        return $this->redirect($url);
    }

}

次に、コントローラールートをrouting.ymlにインポートします

#src/Rm/DemoBundle/Resources/config/routing.yml
apc:
    resource: "@RmDemoBundle/Controller/ApcController.php"
    type:     annotation
    prefix:   /apc

これで、以下の URL を使用して apc キャッシュをクリアできます。

http://yourdomain/apc/cc

注 : @Secure(roles="ROLE_SUPER_ADMIN, ROLE_ADMIN") アノテーション。これにより、apc キャッシュ URL が不正アクセスから保護されます。

于 2014-11-25T07:36:00.307 に答える