Mojolicious模板缓存过时 [英] Mojolicious template cache is stale

查看:93
本文介绍了Mojolicious模板缓存过时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Mojolicious开发一个小型的单页Web应用程序.该应用程序具有与REST-ish API对话的Javascript前端(使用Backbone).源代码的布局大致为:

I'm currently developing a small single-page Web app using Mojolicious. The app has a Javascript frontend (using Backbone) that talks to a REST-ish API; the layout of the source is roughly:

use Mojolicious::Lite;

# ... setup code ...

get '/' => sub {
    my $c = shift;
    # fetch+stash data for bootstrapped collections...
    $c->render('app_template');
};

get '/api_endpoint' => sub {
    my $c = shift;
    # fetch appropriate API data...
    $c->render(json => $response);
};

# ... more API endpoints ...

app->start;

该应用模板使用EP,但使用率极低;唯一的服务器端模板指令只需为自举集合添加JSON.它通过Apache作为纯CGI脚本进行部署. (这不是最佳选择,但仅供内部低流量使用,并且在上下文中存在更复杂的服务器配置问题.)Perl CGI是通过mod_perl配置的.

The app template uses EP, but very minimally; the only server-side template directives just insert JSON for bootstrapped collections. It's deployed via Apache as a plain CGI script. (This isn't optimal, but it's for low-traffic internal use, and more intricate server configuration is problematic in context.) Perl CGI is configured via mod_perl.

这在大多数情况下都有效,但是偶尔渲染器会以某种方式产生想法,认为它应该缓存模板并忽略对其所做的更改. error_log中的调试记录显示正在渲染缓存的模板"而不是普通的正在渲染的模板",并且我对该模板所做的新更改不再出现在浏览器中.我找不到阻止这种情况的可靠方法,尽管它最终会根据我无法识别的条件自行停止.

This works most of the time, but occasionally the renderer somehow gets the idea that it should cache the template and ignore changes to it. The debug records in error_log show "Rendering cached template" rather than the normal "Rendering template", and my new changes to the template stop appearing in the browser. I can't find a reliable way to stop this, though it will eventually stop on its own according to conditions I can't discern.

如何可靠地更改应用程序通知模板?另外,如何完全禁用模板缓存?

How can I make the app notice template changes reliably? Alternatively, how can I disable template caching completely?

推荐答案

如何可靠地更改应用通知模板?

How can I make the app notice template changes reliably?

这就是 morbo 开发服务器的用途. Morbo不会用于实时代码部署,而是用于不断更改代码和模板的开发环境.通常,对实时代码和模板的更改应通过重新启动应用程序服务器(或您的情况下的Apache)来处理. (为此, Hypnotoad 具有热重启功能)

This is what the morbo development server is for. Morbo wouldn't be used for your live code deployment, but for a development environment where you are continually changing your code and templates. Generally changes to live code and templates are meant to be handled by restarting the application server, or Apache in your case. (Hypnotoad has a hot-restart capability for this purpose)

或者,如何完全禁用模板缓存?

Alternatively, how can I disable template caching completely?

为此,请添加以下设置代码(在路由之外,在use Mojolicious::Lite之后):

To do this, add the following setup code (outside of routes, after use Mojolicious::Lite):

app->renderer->cache->max_keys(0);

这篇关于Mojolicious模板缓存过时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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