dongtuwu8548 2011-11-07 14:34
浏览 19
已采纳

PHP缓存结构(如果是HIT则跳过代码块)

Basically, I am implementing own cache system. Ideally, it'll look like this:

$CACHE->start($name);
   //CODE
$CACHE->end();

But that is a holy grail that I do not hope to find. Basically, the $CACHE->start() checks if cache is a hit or a miss, and whether it is a hit, it skips the //CODE until $CACHE->end().

The best I have come so far, is:

if ($CACHE->start($name)) {
   //CODE
}
$CACHE->end();

Since PHP supports anonymous functions, I was thinking of:

$CACHE->make($name, function() {
   //CODE
});

But this code has a problem that code is not in the same variable scope. Any chance to bypass that?

Update: I have since switched to ruby, which allows to pass the block to a function, being perfect for this task.

  • 写回答

3条回答 默认 最新

  • douyi4297 2011-11-14 21:10
    关注

    Zend Framework includes a cache that skips $cache->end() by assuming the remainder of the page is part of the cached content.

    // Default cache ID is calculated from $_SERVER['REQUEST_URI']
    $zendPageCache->start();
    
    // ....
    
    // No need for end
    

    It doesn't fit all use-cases though.

    (A modified version of my comment)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探