向 Zend\Form\Annotation\AnnotationBuilder 添加缓存 [英] Add caching to Zend\Form\Annotation\AnnotationBuilder

查看:23
本文介绍了向 Zend\Form\Annotation\AnnotationBuilder 添加缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我终于在 Windows 上找到了 PHP 5.4.4 的 memcache 二进制文件,我正在加速我目前正在开发的应用程序.

As I've finally found a binary of memcache for PHP 5.4.4 on Windows, I'm speeding up the application I'm currently developing.

我已成功将 memcache 设置为 Doctrine ORM 映射缓存驱动程序,但我需要修复另一个漏洞:使用注释构建的表单.

I've succeeded setting memcache as Doctrine ORM Mapping Cache driver, but I need to fix another leakage: Forms built using annotations.

我正在根据 文档.不幸的是,这需要很多时间,尤其是在为单个页面创建多个表单时.

I'm creating forms according to the Annotations section of the docs. Unfortunately, this takes a lot of time, especially when creating multiple forms for a single page.

是否可以在此过程中添加缓存?我浏览了代码,但似乎 Zend\Form\Annotation\AnnotationBuilder 总是通过反映代码和解析注释来创建表单.提前致谢.

Is it possible to add caching to this process? I've browsed through the code but it seems like the Zend\Form\Annotation\AnnotationBuilder always creates the form by reflecting the code and parsing the annotations. Thanks in advance.

推荐答案

你可能想尝试这样的事情:

You might wanna try something like this:

class ZendFormCachedController extends Zend_Controller_Action
{
    protected $_formId = 'form';

    public function indexAction()
    {
            $frontend = array(
                    'lifetime' => 7200,
                    'automatic_serialization' => true);

            $backend = array('cache_dir' => '/tmp/');
            $cache = Zend_Cache::factory('Core', 'File', $frontend, $backend);

            if ($this->getRequest()->isPost()) {
                    $form = $this->getForm(new Zend_Form);
            } else if (! $form = $cache->load($this->_formId)) {
                    $form = $this->getForm(new Zend_Form);
                    $cache->save($form->__toString(), $this->_formId);
            }

            $this->getHelper('layout')->setLayout('zend-form');
            $this->view->form = $form;
    }

此处找到.

这篇关于向 Zend\Form\Annotation\AnnotationBuilder 添加缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆