代码之家  ›  专栏  ›  技术社区  ›  alexanderpas

如何清空Drupal缓存(没有Devel)

  •  20
  • alexanderpas  · 技术社区  · 16 年前

    如何清空Drupal缓存:

    • Devel模块
    • 没有在新节点中运行一些PHP语句等。
    • 不需要进入数据库本身

    实际上,您如何指导最终用户清除缓存?

    12 回复  |  直到 13 年前
        1
  •  44
  •   Pascal MARTIN    16 年前

    当您以管理员身份登录时 (显然,并非网站的每个用户都有权清除缓存) ,中应该有一页“ 管理>站点配置>表演 ".

    并且,在页面底部,应该有一个按钮(类似于“ 清除缓存数据 )以清除缓存


    作为参考,你可以看看 How to Clear Drupal Server-side cache

        2
  •  20
  •   Niels    16 年前

    您也可以使用 Drush 模块,它允许您使用命令行执行常用的Drupal命令,如“drush cron”或“drush cache clear”。

        3
  •  8
  •   sagesolutions    14 年前

    drupal_flush_all_caches();
    
        4
  •  4
  •   user143520    16 年前

    我有最简单的解决办法。安装admin_菜单模块(实际上不仅仅是为了此目的,一旦安装此模块,您肯定不会后悔,链接: http://drupal.org/project/admin_menu

        5
  •  3
  •   dlamblin    16 年前

    如果您可以通过点击以下按钮获得行为,那将是非常棒的:
    http://drupal.local./admin/settings/performance?op=Clear%20cached%20data

    但是,我确实希望注意通过“管理”菜单进行快捷操作的URL(使用后一部分):
    http://drupal.local. /admin/settings/performance

        6
  •  1
  •   Kevin    16 年前

    按需清算可在管理中完成>站点配置>表演

    当cron在Drupal上运行时,所有缓存都会被清除和重建,而无需人工进行。

    如果这个问题与主题化有关,您应该禁用缓存机制(css/js聚合),并且在进行更改时不必清除缓存数据。

        7
  •  1
  •   Jeffiekins    15 年前

    干得好:

    我不得不卸载“devel”模块(它与特殊菜单项不兼容,我更需要它),所以我自己做了一个。

    在您看到的任何地方,MODULENAME都可以将其替换为模块的名称。

    步骤1: 在“return$items”行之前,添加到HOOK_菜单中的任何模块(最好是自定义模块之一):

    // short cut for flushing the caches:
    $items['flush-cache'] = array(
      'type' => MENU_CALLBACK,
      'title' => t('Flush the cache'),
      'description' => 'MODULENAME Custom Cache Flush',
      'page callback' => 'MODULENAME_flush_cache',
      'access callback' => TRUE,
    );
    

    步骤2: 现在,在同一个模块文件中,它不在任何其他函数的“内部”,添加:

    /**  Page callback  **/
    function MODULENAME_flush_cache() {
      drupal_flush_all_caches();
      return 'Caches were flushed.';
    }
    

    现在,您只需转到站点上的URL“/刷新缓存”即可刷新缓存。(最后一次刷新缓存后,使用旧方法。)

    步骤3: 如果您希望它非常方便,请将以下内容添加到page.tpl.php文件中。您可以将其放置在以下两个位置之间的任意位置<车身>及</车身>。注意:$my_is_test是我在测试系统上使用的一个变量,在生产中是FALSE。如果您没有类似的内容,请将其替换为TRUE或FALSE以打开或关闭:

    <?php if ($my_is_test): ?>
    <a style="text-align:left; position:absolute; right:2px; top:20px;" href="<?=$base_path?>flush-cache" onclick="this.innerHTML = '<b><blink><big>Wait...</big></blink></b>';">flush</a>
    <? endif; ?>
    

    瞧!您可以单击的每个页面的右上角都有一个“刷新”链接。您可以随意更改“右”和“顶”的数量(或者将“右”更改为“左”或将“顶”更改为“底”以将其放在您喜欢的任何位置)。此链接定位仅适用于现代浏览器,但仅适用于您,所以这不应该是个问题,对吗?

        8
  •  1
  •   ansorensen    13 年前

    http://www.drupalgardens.com/content/clear-all-caches-not-working

    网站周围还有另一层缓存,可以“清除所有内容” “缓存”不会影响,你是对的。这是存储的层

    如果出于测试目的希望绕过缓存,可以添加 访问example.drupalgardens.com/foo?bar=baz或任何其他随机文本 设置为?xxxxx=xxxxx。

    这对我很有帮助,因为我遇到了在配置下清除缓存的问题>表演似乎没有帮助。

        9
  •  1
  •   Sebastian Chedal    12 年前

    上面的代码是针对Drupal6的。

    对于Drupal 7,刷新缓存模块如下所示:

    <?php 
    /**
     * Implementation of hook_menu()
     */
    function flush_cache_menu() {
      $items = array();
    
      $items['flush-cache'] = array(
      'type' => MENU_NORMAL_ITEM,
      'title' => t('Flush the cache'),
      'description' => 'Flush all website caches to make sure it updates to relect '.
        'your recent changes.',
      'page callback' => 'flush_cache_custom_callback',
      'access callback' => user_access('flush cache'),
      );
    
      return $items;
    }
    
    /**
     * Implementation of hook_permission()
     */
    function flush_cache_permission() {
      return array(
        'administer my module' => array(
          'title' => t('flush cache module'),
          'description' => t('Content admin flush cache.'),
        ),
      );
    }
    
    /**
     * Function that flushes the cache
     */
    function flush_cache_custom_callback() {
      drupal_flush_all_caches();
      return 'Caches were flushed.';
    }
    

    sitename.com/flush-cache

    当您不希望客户端访问“管理”菜单,但仍希望客户端能够刷新缓存时,这是最好的选择。

        10
  •  0
  •   Shaun Dychko    14 年前

    以下模块创建一个菜单项,该菜单项仅可由具有“刷新缓存”权限的用户访问,此模块在常规用户权限页面上提供该权限。

    /**
     * Implementation of hook_menu()
     */
    function flush_cache_menu() {
      $items = array();
    
      $items['flush-cache'] = array(
      'type' => MENU_NORMAL_ITEM,
      'title' => t('Flush the cache'),
      'description' => 'Flush all website caches to make sure it updates to relect '.
        'your recent changes.',
      'page callback' => 'flush_cache_custom_callback',
      'access callback' => user_access('flush cache'),
      );
    
      return $items;
    }
    
    /**
     * Implementation of hook_perm()
     */
    function flush_cache_perm() {
      return array('flush cache');
    }
    
    /**
     * Function that flushes the cache
     */
    function flush_cache_custom_callback() {
      drupal_flush_all_caches();
      return 'Caches were flushed.';
    }
    
        11
  •  0
  •   rockstardev    10 年前

    在Drupal8中,管理菜单模块还没有准备好使用。它可能会被Drupal的“工具栏”所取代。因此,现在没有简单的方法可以清除缓存,而不实际执行以下操作:

    admin/config/development/performance
    

    this module ,但正如您所看到的,它仍然需要一些工作。我让它工作,但不得不做一些调整。

        12
  •  -1
  •   LOTUSMS    10 年前

    使用drush和以下命令:drushcall

    如果使用Boost进行缓存,则需要更加具体:

    drush @alias_name cc all
    
    推荐文章