【问题标题】:Drupal 7 Cache BustingDrupal 7 缓存破坏
【发布时间】:2013-02-01 15:24:08
【问题描述】:

我有一个外部非 Drupal 网站 members.example.com,如果受众成员登录该网站,它会设置一个 cookie。它设置了一个对 Drupal 站点可见的 cookie:

$_COOKIE['name'] = '约翰·史密斯';

我想知道 members.example.com 登录用户可以访问 Drupal 站点 www.example.com 上的高级内容。我还想在网站的眉毛部分按名字给登录的会员。

问题是,在登录非 Drupal 站点 members.example.com 并返回 Drupal 站点 www.example.com 后,Drupal 仍在缓存很多内容,并且无法识别用户现在已经设置了 $_COOKIE['name']。

我有:

将settings.php中的cookie域设置为'example.com'

试图破坏同样拥有 cookie 的匿名 Drupal 用户的缓存:

 /**
  * Implements hook_init()
  */
function caplogin_init() {

  // Check for cookie if it's set to 'loggedout':
  if (isset($_COOKIE['name'])) {
    if (strpos($_COOKIE['name'],'loggedout') !== FALSE) {
      // Log them out on the www site too:
      setcookie('name', '', 1, '/', '.example.com');
      global $user;
      if ($user->uid > 0) {
        user_logout();
      }
      $reason = 'Members server logout.';
      _caplogin_no_cache($reason);
      drupal_set_message(t('You have been logged out of the site. Thanks for visiting!'));
    }
    else {
      $reason = 'Member logged in internal server.';
      _caplogin_no_cache($reason);
    }
  }
}

还有……

function _caplogin_no_cache($reason) {
    if (!$reason) {
      $reason = 'no-cache called by site functionality.';
    }
    drupal_add_http_header('X-DRCC-No-Cache-Reason', $reason);
    drupal_add_http_header('Pragma', 'no-cache');
    drupal_add_http_header('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT');
    drupal_add_http_header('Cache-Control', 'no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0');
    drupal_add_http_header('Expires', 'Sat, 02 Jan 1971 00:00:00 GMT');
 }

我还安装了 Devel 模块并(用于测试)选中了 ON 复选框以在每次页面加载时重建主题缓存。没有运气。

如果你添加一个虚假的查询字符串,它确实会破坏缓存,例如http://www.example.com/?sdjaSDH

但客户端需要 Drupal 识别用户已登录外部 members.example.com 站点的功能。

我还能尝试什么?

【问题讨论】:

    标签: caching drupal-7 browser-cache


    【解决方案1】:

    这样做

    $GLOBALS['conf']['cache'] = FALSE; 
    

    帮助?

    您可能需要将此代码添加到 hook_boot() 或 hook_init() 并根据您的需要进行一些开关。

    【讨论】:

      猜你喜欢
      • 2012-03-09
      • 1970-01-01
      • 1970-01-01
      • 2020-05-19
      • 1970-01-01
      • 2015-10-02
      • 2011-06-13
      • 2016-02-16
      • 1970-01-01
      相关资源
      最近更新 更多