基础篇12. 关闭缓存,检查网站是否出错

我们回到settings.local.php文件中,把67行和84行的代码前面的注释符号删除,关闭页面缓存。再次使用Drupal console的清空缓存命令来清空缓存。(由于版本的差异,你的代码中,对应语句的行数可能有所变化,但是差别应该不大)

/**
 * Disable the render cache (this includes the page cache).
 *
 * Note: you should test with the render cache enabled, to ensure the correct
 * cacheability metadata is present. However, in the early stages of
 * development, you may want to disable it.
 *
 * This setting disables the render cache by using the Null cache back-end
 * defined by the development.services.yml file above.
 *
 * Do not use this setting until after the site is installed.
 */
 $settings['cache']['bins']['render'] = 'cache.backend.null';
/**
 * Disable Dynamic Page Cache.
 *
 * Note: you should test with Dynamic Page Cache enabled, to ensure the correct
 * cacheability metadata is present (and hence the expected behavior). However,
 * in the early stages of development, you may want to disable it.
 */
 $settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';

然后切换到浏览器,刷新首页,如果这个时候首页能够正常打开,就可以了,你不应该看到首页有任何变化。

请注意,为了正确的加载service,比如 twig debug 和禁用缓存,我们先创建了local.services.yml文件,

并且在文件中将cache设置为false,然后第一次清空了缓存。接着,我们又回到settings.local.php文件中开启第67行和84行的代码,并第二次清空了缓存。这里的操作顺序是非常重要的。你最好按照这个步骤来操作,不然最后刷新首页的时候会发生错误,整个网站就挂了。

网上虽然有一些英文博客说用rebuild.php可以解决问题,但是,我实际测试过,在这个例子和这个版本的Drupal8中是无法解决问题的。网上很多其他讲述drupal8配置本地服务的文档都没有提到这个问题,所以很容易把初学者带到坑里。

因此,我们在这里刷新首页,要检查的并不是首页或者元素检查区域有什么变化,而是检查网站有没有出错。

至于系统是否已经关闭缓存,我们回头再来检测。

本书共102小节。


目前全部收费内容共235.00元。购买全部

评论 (0)