在一个拥有大量流量的新项目中,我们正在思考如何构建我们的Symfony2应用程序以利用缓存,并准备好在未来更积极.我很想知道你的意见.
假设用户向页面请求地点列表.这个页面有:
- list
- common data (title, author, description)
- user data (the user likes the list + other data)
- first 20 places
- common data (title, photo of each place)
- user data (the rates of the user for those places)
Run Code Online (Sandbox Code Playgroud)
HTML可能是这样的:
<html>...
<body>
<header>
...
<!-- Embed the top user menu -->
<esi:include src="http://example.com/profile/menu" />
...
</header>
<content>
...
common data of the list
...
<!-- Embed the common data of the first 20 places, the …Run Code Online (Sandbox Code Playgroud) 我正在努力让ESI包含在JSON上下文中被替换.
以下工作正常.导致ESI标签被实际内容所取代.
<esi:include src="http://domain.com/esipath/" />
Run Code Online (Sandbox Code Playgroud)
这不起作用.ESI标签未被替换.
{
"test": "<esi:include src="http://domain.com/esipath/" />"
}
Run Code Online (Sandbox Code Playgroud)
我在google上找到了一些资源,并且可能的解决方案似乎设置esi_syntax为0x3,以便varnish跳过检查有效的XML.这似乎不适用于Varnish 4.当我使用运行时参数启动deamon时,我收到以下错误.
Error: Unknown parameter "esi_syntax".
Run Code Online (Sandbox Code Playgroud)
Varnish 4中是否弃用此设置?
任何想法让这个工作?
我正在计划我的缓存策略,我正在深入研究ESI以确定它是否符合我的需求.
今天出现了这些问题:
{% render '...' with {}, {'standalone': true} %}.据我所知,生成的页面必须等待所有这些页面,但是它需要的时间,它是否与包含的最慢页面类似,还是类似于所有这些包含的总和?如果我使用Varnish来缓存我的整个文档,你会建议我通过什么机制增加页面查看次数.
例如,让我知道我有一个拍卖列表,如ebay,我想缓存整个页面,因为我知道它永远不会改变.
那你怎么会增加这个列表的页面浏览量.
可以说我的应用程序是从Zend Framework运行的.将ESI(Edge Side Include)设置为node.js服务器是否正确,该服务器会增加Redis中的页面查看次数?
我正在寻找能够100%支持的东西,并且能够提供准确的页面查看请求编号.(我也不关心重复的请求,我将在我的应用程序逻辑中处理它,以防止一个IP阻止页面查看计数).
我不知道我在做什么了.我有很多问题,我不知道从哪里开始.这是我的配置:
varnishd (varnish-3.0.3 revision 9e6a70f)
Server version: Apache/2.2.22 (Unix)
Symfony 2.3.1
Run Code Online (Sandbox Code Playgroud)
首先,我AppCache在app.php文件中禁用了Symfony ,该文件被用作反向代理而不是Varnish.
这是我的清漆配置:
Varnish (80) <--> Apache (8080)
# /etc/varnish/default.vcl
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
if (req.http.Cache-Control ~ "no-cache") {
return (pass);
}
if (!(req.url ~ "^/dashboard/")) {
unset req.http.Cookie;
}
# Remove has_js and Google Analytics __* cookies.
set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(_[_a-z]+|has_js)=[^;]*", "");
# Remove a ";" prefix, if present.
set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
#set …Run Code Online (Sandbox Code Playgroud) 我想在symfony2中使HTTP缓存无效.我使用以下方法:
protected function invalidateCache($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PURGE');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $status == 200;
}
Run Code Online (Sandbox Code Playgroud)
这工作,没问题.但是当我使用ESI包括我的controller()函数(而不是path())时:
{{ render_esi(controller('AcmeDemoBundle:Default:index')) }}
Run Code Online (Sandbox Code Playgroud)
如何获取控制器功能生成的URL?或者我如何使该esi请求的缓存响应无效?
我在我的Symfony 3应用程序中启用了ESI,我将其用于app_dev.php:
$kernel = new AppKernel('dev', true);
$kernel = new AppCache($kernel);
Run Code Online (Sandbox Code Playgroud)
现在我有config.yml:
framework:
esi: { enabled: true }
fragments: { path: /_fragment }
Run Code Online (Sandbox Code Playgroud)
在我的控制器中:
/**
* @Route("/foo/bar/{fooId}", name="AppBundle_Foo_bar")
*/
public function barAction(int $fooId, Request $request)
{
//some database querying from repositroy
$response = $this->render('AppBundle:Foo:bar.html.twig',['foo' => $foo]);
$response->setETag(md5($response->getContent()));
$response->setPublic();
$response->isNotModified($request);
return $response;
}
Run Code Online (Sandbox Code Playgroud)
这是bar.html.twig我要缓存的view(),如下所示:
{{foo}}
Run Code Online (Sandbox Code Playgroud)
现在,我有另一种渲染主视图的方法.
/**
* @Route("/baz/{fooId}", name="AppBundle_Foo_baz")
* @Template
*/
public function bazAction(int $fooId)
{
return [
'fooId' => $fooId
];
} …Run Code Online (Sandbox Code Playgroud) 是否可以在ESI与Symfony 2中使用验证缓存?
如果查看HttpFoundation Response类,可以看到isNotModified的工作原理:
/**
* Determines if the Response validators (ETag, Last-Modified) match
* a conditional value specified in the Request.
*
* If the Response is not modified, it sets the status code to 304 and
* removes the actual content by calling the setNotModified() method.
*
* @param Request $request A Request instance
*
* @return Boolean true if the Response validators match the Request, false otherwise
*
* @api
*/
public function isNotModified(Request $request) …Run Code Online (Sandbox Code Playgroud) 我想知道是否存在类似私有ESI片段的东西.在我读到的文档中:
我不完全理解我是否能够或不能按用户缓存页面的某些部分.有人可以解释一下吗?
提前致谢!
我对这个问题很迷茫,我不知道问题出在哪里,所以,我希望你能帮助我。
我有一个带有 symfony 的 HTTP BASIC 身份验证,我正在尝试访问受此身份验证保护的 URL,在 Drupal 页面中带有一个标记。每个请求都发送到 Varnish
我在 url 中提供用户名和密码,如下所示:
<esi:include src="http://admin:adminpass@api.dev:8081/app.php/next"/>
Run Code Online (Sandbox Code Playgroud)
在我的 varnish 配置文件中,我只有 auth.http 的那几行:
if (req.http.Authorization) {
return (pass);
}
Run Code Online (Sandbox Code Playgroud)
我的 Symfony 后端在没有 http 身份验证的情况下运行良好,并且当没有 Varnish 和 esi 标签时,http 身份验证运行良好。
如果有人知道这个问题,请告诉我,即使是错误的 =)
我故意尝试使用Newtonsoft Json创建无效的JSON,以便放置ESI包含标签,该标签将获取另外两个JSON节点。
这是我的JsonConverter的WriteJson方法:
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
mApiResponseClass objectFromApi = (mApiResponseClass)value;
foreach (var obj in objectFromApi.GetType().GetProperties())
{
if (obj.Name == "EsiObj")
{
writer.WriteRawValue(objectFromApi.EsiObj);
}
else
{
writer.WritePropertyName(obj.Name);
serializer.Serialize(writer, obj.GetValue(value, null));
}
}
}
Run Code Online (Sandbox Code Playgroud)
mApiResponseClass中的EsiObj只是一个字符串,但是需要将其写入JSON响应中,以便在不使用任何属性名的情况下进行解释-这样HSI ESI才能起作用。
当然,这会导致Json Writer发生异常,其值为:
Newtonsoft.Json.JsonWriterException:'状态对象中的令牌未定义将导致无效的JSON对象。路径“。”
有没有办法解决?
理想的输出是JSON格式,从技术上讲是无效的,并且看起来像这样:
{
value:7,
string1:"woohoo",
<esi:include src="/something" />
Song:["I am a small API","all i do is run","but from who?","nobody knows"]
}
Run Code Online (Sandbox Code Playgroud)
编辑: 使用ESI,我们可以使单个响应具有不同的缓存长度-即,我们可以将可以缓存很长时间的数据放置在JSON的某些部分中,并且仅获取更新的部分,例如那些依赖客户端的部分特定的数据。ESI不是特定于HTML的。(如下所示)通过支持这些标签的Varnish运行。不幸的是,要求我们仅发出1个文件作为响应,并且不需要客户进一步的要求。我们也不能更改响应-所以我不能只添加一个专门包含其他节点的JSON节点。
编辑2: “更多json节点”部分是通过ESI解决的,它向我们的后端进一步请求用户/客户端特定的数据,即另一个端点。预期的结果是,我们随后将原始JSON文档与后来的JSON文档无缝地合并在一起。(这样,原始文档可能会很旧,而特定于客户的文档可能会很新)
编辑3: 端点/ something将输出类似JSON的片段,例如:
teapots:[ {Id: 1, WaterLevel: 100, Temperature: 74, ShortAndStout: …Run Code Online (Sandbox Code Playgroud)