clean example


        $this->db->executeQuery($sql);
    }

    /** * Clear search cache */
    public function clearConfigCache()
    {
        $capabilities = $this->cache->getBackend()->getCapabilities();
        if (!empty($capabilities['tags'])) {
            $this->cache->clean(
                Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG,
                [
                    self::ITEM_TAG_CONFIG,
                    self::ITEM_TAG_PLUGIN,
                ]
            );
        } else {
            $this->cache->clean();
        }
    }

    
$entity = $args->get('entity');

        $this->addTagsConfigValue($entity);
    }

    public function onKernelTerminate(Enlight_Event_EventArgs $args): void
    {
        if (\count($this->clearTags) === 0) {
            return;
        }

        $this->cacheManager->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array_keys($this->clearTags));
        $this->clearTags = [];
    }

    private function addTagsConfigValue(Value $value): void
    {
        if (!$value->getElement()->getFormId() || !$value->getElement()->getForm()->getPlugin()) {
            return;
        }

        $name = strtolower($value->getElement()->getForm()->getPlugin()->getName());

        
file_get_contents($path . 'source_url_old.min.js.optimized.js'),
      ],
    ];
  }

  /** * Tests cleaning of a JS asset group containing 'type' => 'file'. * * @dataProvider providerTestClean */
  public function testClean($js_asset$expected) {
    $this->assertEquals($expected$this->optimizer->clean($js_asset));
  }

  /** * Provides data for the JS asset optimize test. * * @see \Drupal\Core\Asset\JsOptimizer::optimize() * * @returns array * An array of test data. */
  public function providerTestOptimize() {
    
      if (isset($js_asset['minified']) && $js_asset['minified']) {
        $data .= file_get_contents($js_asset['data']);
      }
      else {
        $data .= $this->optimizer->optimize($js_asset);
      }
      // Append a ';' and a newline after each JS file to prevent them from       // running together.       $data .= ";\n";
    }
    // Remove unwanted JS code that causes issues.     return $this->optimizer->clean($data);
  }

}

    public static function clearCache($tag = null)
    {
        if (self::$_cacheTags) {
            if ($tag == null) {
                $tag = 'Zend_Translate';
            }

            self::$_cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array($tag));
        } else {
            self::$_cache->clean(Zend_Cache::CLEANING_MODE_ALL);
        }
    }

    /** * Returns the adapter name * * @return string */
    abstract public function toString();

    
public static function removeCache()
    {
        self::$_cache = null;
    }

    /** * Clears all set cache data */
    public static function clearCache()
    {
        if (self::$_cacheTags) {
            self::$_cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, ['Zend_Locale']);
        } else {
            self::$_cache->clean(Zend_Cache::CLEANING_MODE_ALL);
        }
    }

    /** * Disables the cache * * @param unknown_type $flag */
    public static function disableCache($flag)
    {
ini_restore('memory_limit');
    }

    /** * Allows to set a Shopware config * * @param bool|float|int|string|null $value */
    protected function setConfig(string $name$value): void
    {
        Shopware()->Container()->get('config_writer')->save($name$value);
        Shopware()->Container()->get(Zend_Cache_Core::class)->clean();
        Shopware()->Container()->get(Shopware_Components_Config::class)->setShop(Shopware()->Shop());
    }
}

    public function clearCacheAction()
    {
        $cache = $this->Request()->getPost('cache', []);

        $cacheInstance = $this->container->get('cache');

        $capabilities = $cacheInstance->getBackend()->getCapabilities();

        if (empty($capabilities['tags'])) {
            if ($cache['config'] === 'on' || $cache['template'] === 'on') {
                $cacheInstance->clean();
            }
        } else {
            $tags = [];
            if ($cache['config'] === 'on' || $cache['backend'] === 'on') {
                $tags[] = CacheManager::ITEM_TAG_CONFIG;
                $tags[] = CacheManager::ITEM_TAG_PLUGIN;
            }
            if ($cache['search'] === 'on') {
                $tags[] = CacheManager::ITEM_TAG_SEARCH;
            }
            if ($cache['backend'] === 'on') {
                
    // --------------------------------------------------------------------
    /** * Instructs the class to ignore all * requests to cache an item, and always "miss" * when checked for existing data. * * @return $this */
    public function bypass(bool $bypass = true)
    {
        $this->clean();
        $this->bypass = $bypass;

        return $this;
    }

    // --------------------------------------------------------------------     // Additional Assertions     // --------------------------------------------------------------------
    /** * Asserts that the cache has an item named $key. * The value is not checked since storing false or null * values is valid. */
$handler = $params[0] ?? $config->handler;

        if (array_key_exists($handler$config->validHandlers)) {
            CLI::error($handler . ' is not a valid cache handler.');

            return;
        }

        $config->handler = $handler;
        $cache           = CacheFactory::getHandler($config);

        if ($cache->clean()) {
            // @codeCoverageIgnoreStart             CLI::error('Error while clearing the cache.');

            return;
            // @codeCoverageIgnoreEnd         }

        CLI::write(CLI::color('Cache cleared.', 'green'));
    }
}

    public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
    {
        switch($mode) {
            case Zend_Cache::CLEANING_MODE_ALL:
                $boolFast = $this->_fastBackend->clean(Zend_Cache::CLEANING_MODE_ALL);
                $boolSlow = $this->_slowBackend->clean(Zend_Cache::CLEANING_MODE_ALL);
                return $boolFast && $boolSlow;
                break;
            case Zend_Cache::CLEANING_MODE_OLD:
                return $this->_slowBackend->clean(Zend_Cache::CLEANING_MODE_OLD);
            case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
                $ids = $this->_slowBackend->getIdsMatchingTags($tags);
                $res = true;
                foreach ($ids as $id) {
                    $bool = $this->remove($id);
                    $res = $res && $bool;
                }

    protected function doDelete($id)
    {
        return $this->cache->remove($this->prefix . md5($id));
    }

    /** * Deletes all cache entries. */
    protected function doFlush()
    {
        $this->cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, $this->tags);

        return true;
    }

    /** * Retrieves cached information from data store * * @since 2.2 */
    protected function doGetStats()
    {
        
                if (isset($js_asset['minified']) && $js_asset['minified']) {
                  $data .= file_get_contents($js_asset['data']);
                }
                else {
                  $data .= $this->optimizer->optimize($js_asset);
                }
                // Append a ';' and a newline after each JS file to prevent them                 // from running together.                 $data .= ";\n";
              }
              // Remove unwanted JS code that cause issues.               $data = $this->optimizer->clean($data);
              // Dump the optimized JS for this group into an aggregate file.               $uri = $this->dumper->dump($data, 'js');
              // Set the URI for this group's aggregate file.               $js_assets[$order]['data'] = $uri;
              // Persist the URI for this aggregate file.               $map[$key] = $uri;
              $this->state->set('system.js_cache_files', $map);
            }
            else {
              // Use the persisted URI for the optimized JS file.               $js_assets[$order]['data'] = $uri;
            }

  protected function processFile($css_asset) {
    $contents = $this->loadFile($css_asset['data'], TRUE);
    if ($css_asset['media'] !== 'print' && $css_asset['media'] !== 'all') {
      $contents = '@media ' . $css_asset['media'] . '{' . $contents . '}' . "\n";
    }
    $contents = $this->clean($contents);

    // Get the parent directory of this file, relative to the Drupal root.     $css_base_path = substr($css_asset['data'], 0, strrpos($css_asset['data'], '/'));
    // Store base path.     $this->rewriteFileURIBasePath = $css_base_path . '/';

    // Anchor all paths in the CSS with its base URL, ignoring external and absolute paths and paths starting with '#'.     return preg_replace_callback('/url\(\s*[\'"]?(?![a-z]+:|\/+|#|%23)([^\'")]+)[\'"]?\s*\)/i', [$this, 'rewriteFileURI']$contents);
  }

  /** * Loads the stylesheet and resolves all @import commands. * * Loads a stylesheet and replaces @import commands with the contents of the * imported file. Use this instead of file_get_contents when processing * stylesheets. * * The returned contents are compressed removing white space and comments only * when CSS aggregation is enabled. This optimization will not apply for * color.module enabled themes with CSS aggregation turned off. * * Note: the only reason this method is public is so color.module can call it; * it is not on the AssetOptimizerInterface, so future refactorings can make * it protected. * * @param $file * Name of the stylesheet to be processed. * @param $optimize * Defines if CSS contents should be compressed or not. * @param $reset_basepath * Used internally to facilitate recursive resolution of @import commands. * * @return string * Contents of the stylesheet, including any resolved @import commands. */

    protected function clearCache($cache)
    {
        $capabilities = $this->cache->getBackend()->getCapabilities();

        if ($cache === 'all') {
            $this->cache->clean();

            $this->cacheManager->clearHttpCache();
            $this->cacheManager->clearConfigCache();
            $this->cacheManager->clearTemplateCache();
            $this->cacheManager->clearProxyCache();
            $this->cacheManager->clearSearchCache();
            $this->cacheManager->clearOpCache();

            return;
        }

        
Home | Imprint | This part of the site doesn't use cookies.