• Drupal是如何避免页面缓存保存Message信息的


    函数page_get_cache代码:

    function page_get_cache($status_only = FALSE) {
      static $status = FALSE;
      global $user, $base_root;
    
      if ($status_only) {
        return $status;
      }
      $cache = NULL;
    
      if (!$user->uid && $_SERVER['REQUEST_METHOD'] == 'GET' && count(drupal_set_message()) == 0 && $_SERVER['SERVER_SOFTWARE'] !== 'PHP CLI') {
        $cache = cache_get($base_root . request_uri(), 'cache_page');
    
        if (empty($cache)) {
          ob_start();
          $status = TRUE;
        }
      }
    
      return $cache;
    }

    可见,当message为0时,才会从cache中获取缓存。

    再来看看page_set_cache函数,该函数负责保存cache

     1 function page_set_cache() {
     2   global $user, $base_root;
     3 
     4   if (!$user->uid && $_SERVER['REQUEST_METHOD'] == 'GET' && page_get_cache(TRUE)) {
     5     // This will fail in some cases, see page_get_cache() for the explanation.
     6     if ($data = ob_get_contents()) {
     7       if (variable_get('page_compression', TRUE) && extension_loaded('zlib')) {
     8         $data = gzencode($data, 9, FORCE_GZIP);
     9       }
    10       ob_end_flush();
    11       cache_set($base_root . request_uri(), $data, 'cache_page', CACHE_TEMPORARY, drupal_get_headers());
    12     }
    13   }
    14 }

    其中有行代码page_get_cache(TRUE),来判断是否能找到cache,如果不能找到,返回TRUE,这时候才会做页面的缓存。而当drupal_set_message()不为空时,page_get_cache(TRUE)始终都会返回FALSE,可见drupal在获取页面缓存和设置页面缓存时,都对是否有message做了判断,只有message为空时才会设置缓存、或者获取缓存。

  • 相关阅读:
    ServletContext笔记
    Session笔记
    Cookie笔记
    递归实现取数组最大值
    栈结构实现队列结构
    返回栈中最小元素的两种实现O(1)
    数组实现不超过固定大小的队列(环形数组)
    双向链表实现栈和队列
    Windows Server 2008 R2 / Windows Server 2012 R2 安装 .NET Core 3.1
    Windows 7 / Windows Server 2008 R2 升级至 SP1
  • 原文地址:https://www.cnblogs.com/merryfreespace/p/3819414.html
Copyright © 2020-2023  润新知