开发者

c# outputcache equivalent in php?

开发者 https://www.devze.com 2023-03-18 03:15 出处:网络
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.ie: the chat cache for id 1 shouldnt be the

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. ie: the chat cache for id 1 shouldnt be the same as id2, since id1 doesnt need to see id2s private messages.

In C#, you can use something akin to:

<%@ 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.

Is there such a thing in php?


PHP doesn't have anything like output caching built in; 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.

If you're up to writing your own implementation, I'd look into memcached to cache your data; then you could just create keys like this for your cached HTML:

$cachekey = "chat_param1:" . $param1 . '-param3:' . $param3);

That way you have a unique key for each possible value of param1 and param3.

0

精彩评论

暂无评论...
验证码 换一张
取 消