简体   繁体   English

c# 输出缓存等效于 php?

[英]c# outputcache equivalent in php?

I am trying to figure out how to cache 'chat' for a site that uses php, and the variables passed need to have unique versions per variable.我试图弄清楚如何为使用 php 的站点缓存“聊天”,并且传递的变量需要每个变量都有唯一的版本。 ie: the chat cache for id 1 shouldnt be the same as id2, since id1 doesnt need to see id2s private messages.即:id 1 的聊天缓存不应与 id2 相同,因为 id1 不需要查看 id2 的私人消息。

In C#, you can use something akin to:在 C# 中,您可以使用类似于:

<%@ OutputCache Duration="4" VaryByParam="param1;param3" %>

This caches the page for 4 seconds, and will cache unique copies if the param1 and param3 are different between the cached pages.这会将页面缓存 4 秒,如果缓存页面之间的 param1 和 param3 不同,则会缓存唯一副本。

Is there such a thing in php? php中有这样的东西吗?

PHP doesn't have anything like output caching built in; PHP 没有像 output 这样的内置缓存; you'll have to either write your own implementation (which isn't too difficult for something like what you're talking about) or use an existing implementation.您必须编写自己的实现(这对于您正在谈论的东西来说并不太难)或使用现有的实现。 I believe that the Smarty templating engine has something similar built in, but it may be too late for you to implement something like that without a lot of trouble.我相信 Smarty 模板引擎内置了类似的东西,但是如果你没有很多麻烦地实现类似的东西可能为时已晚。

If you're up to writing your own implementation, I'd look into memcached to cache your data;如果您准备编写自己的实现,我会研究 memcached 来缓存您的数据; then you could just create keys like this for your cached HTML:那么您可以为缓存的 HTML 创建这样的密钥:

$cachekey = "chat_param1:". $cachekey = "chat_param1:"。 $param1. $参数1。 '-param3:'. '-param3:'。 $param3); $参数3);

That way you have a unique key for each possible value of param1 and param3.这样,对于 param1 和 param3 的每个可能值,您都有一个唯一的键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM