【问题标题】:Cache drupal system pages缓存 drupal 系统页面
【发布时间】:2011-03-11 07:41:14
【问题描述】:

有没有办法为 授权用户 缓存 drupal 系统页面(例如分类/术语/%、论坛/%、节点)而无需核心破解?

【问题讨论】:

    标签: drupal caching drupal-7


    【解决方案1】:

    对于drupal 6,有http://drupal.org/project/authcache。我不相信 drupal 7 的模块已经准备好了。

    【讨论】:

      【解决方案2】:

      您可以在您的自定义模块上启动hook_menu_alter,然后您可以从那里对该路径做任何您想做的事情(分类/术语/%)。

      检查这些路径的回调函数是什么。例如:

      mysql>
      select * from menu_router where path like '%taxonomy/term/%';
      

      它说页面回调是taxonomy_term_page。您不需要将所有代码复制到您的自定义函数中,您需要做的就是这样:

      function mymodule_menu_alter(&$items) {
        // Route taxonomy/term/% to my custom caching function.
        $items['taxonomy/term/%']['page callback'] = 'mymodule_cached_taxonomy_term_page';
      }
      
      function mymodule_cached_taxonomy_term_page($term) {
        // Retrieve from persistent cache.
        $cache = cache_get('taxonomy_term_'. $term); 
      
        // If data hasn't expired from cache.
        if(!empty($cache->data) && ($cache->created < $cache->expire)) {
          return $cache->data;
        } else {
        // Else rebuild the cache.
          $term_page = taxonomy_term_page($term);
          cache_set('taxonomy_term_'. $term, $term_page, 'cache_page', strtotime('+30 minute'));
          return $term_page;
        }
      }
      

      如果走这条路,您将需要熟悉cache_getcache_set。您可能还想查看 Lullabot 的出色缓存 article

      您可以对 forum/%、node 以及您想要的所有其他内容采用相同的方法。快乐的缓存!

      【讨论】:

      • 我想过这样的方式。但是 taxonomy_term_page 不仅返回 html 页面代码,它还创建面包屑并添加提要。它在 mymodule_cached_taxonomy_term_page 中不起作用。其他回调函数还可以使用drupal_set_title、drupal_add_js、drupal_add_css等。
      • 我知道,我也看到了 taxonomy_term_page 代码 =(。如果你不像我上面建议的那样缓存 taxonomy_term_page 的结果怎么样,如果你深入研究那个函数怎么样,并且有选择地将您需要的代码复制到自定义函数中,然后单独调用 feeds 函数?您尝试过吗?让我们知道您发现了什么。
      • 是的,我对 taxonomy_term_page 使用了类似的代码。它工作正常。现在我正在寻找缓存其他核心页面(节点、节点/%、论坛)的解决方案。我不想将所有 drupal 核心回调函数移动到我的模块中。 )
      • 就 drupal 核心输出缓存而言,Drupal 为您提供匿名用户服务 (setup)。对于经过身份验证的用户,我会尝试@mizru 推荐的(authcache)。
      • 更多有用信息:2bits.com/articles/…
      猜你喜欢
      • 2011-05-11
      • 1970-01-01
      • 1970-01-01
      • 2011-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      相关资源
      最近更新 更多