Changeset 115258 in spip-zone


Ignore:
Timestamp:
May 6, 2019, 10:22:51 AM (2 weeks ago)
Author:
cedric@…
Message:

Mise a jour de scssphp, qui inclue une petite optimisation du cache: sur var_mode=css on ne refresh un cache qu'une seule fois et on peut ensuite l'utiliser, ce qui permet de ne parser les fichiers modifies qu'une seule fois
Accelere sensiblement la mise a jour si on a plusieurs scss independante mais qui inclue des morceaux en commun (variables, mixins…)

A noter que le var_mode=css reste utile dans un seul scenario : si on duplique une feuille existante pour la surcharger dans le path, il faudra passer par là pour que le compilateur voit le nouveau fichier et le prenne en compte.
Autrement toute modification d'un fichier utilise dans la compilation provoquera la mise a jour de la css compilee avec un simple var_mode=calcul

Location:
_plugins_/scssphp/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • _plugins_/scssphp/trunk/lib/scssphp/src/Cache.php

    r115043 r115258  
    1515
    1616/**
    17  * The scss cacher.
    18  *
    19  * In summary:
    20  *
    21  * TODO
     17 * The scss cache manager.
     18 *
     19 * In short:
     20 *
     21 * allow to put in cache/get from fache a generic result from a known operation on a generic dataset,
     22 * taking in account options that affects the result
     23 *
     24 * The cache manager is agnostic about data format and only the operation is expected to be descripted by string
     25 *
    2226 */
    2327
     
    3943    public static $prefix = 'scssphp_';
    4044
     45    // force a refresh : 'once' for refreshing the first hit on a cache only, true to never use the cache in this hit
    4146    public static $force_refresh = false;
    4247
    4348    // specifies the number of seconds after which data cached will be seen as 'garbage' and potentially cleaned up
    4449    public static $gc_lifetime = 604800;
     50
     51
     52    // array of already refreshed cache if $force_refresh==='once'
     53    protected static $refreshed = [];
    4554
    4655
     
    7685
    7786    /**
    78      * Generic get
    79      *    Get the previous computed result of $what, affected by $options
     87     * Get the cached result of $operation on $what, which is known as dependant from the content of $options
    8088     *
    8189     * @param string $operation
    82      *   parse, compile?
     90     *   parse, compile...
    8391     * @param $what
    84      *  content key (filename to be treated?)
     92     *  content key (filename to be treated for instance)
    8593     * @param array $options
    8694     *  any option that affect the operation result on the content
     
    94102        $fileCache = self::$cache_dir . self::cacheName($operation, $what, $options);
    95103
    96         if (! self::$force_refresh
     104        if ((! self::$force_refresh || (self::$force_refresh === 'once' && isset(self::$refreshed[$fileCache])))
    97105          and file_exists($fileCache)) {
    98106            $cache_time = filemtime($fileCache);
     
    110118    }
    111119
     120    /**
     121     * Put in cache the result of $operation on $what, which is known as dependant from the content of $options
     122     *
     123     * @param string $operation
     124     * @param $what
     125     * @param $value
     126     * @param array $options
     127     */
    112128    public function setCache($operation, $what, $value, $options = array())
    113129    {
     
    117133        $c = serialize($c);
    118134        file_put_contents($fileCache, $c);
    119     }
    120 
    121 
     135
     136        if (self::$force_refresh === 'once') {
     137            self::$refreshed[$fileCache] = true;
     138        }
     139    }
     140
     141
     142    /**
     143     * get the cachename for the caching of $opetation on $what, which is known as dependant from the content of $options
     144     * @param string $operation
     145     * @param $what
     146     * @param array $options
     147     * @return string
     148     */
    122149    private static function cacheName($operation, $what, $options = array())
    123150    {
     
    139166
    140167
     168    /**
     169     * Check that the cache dir is existing and writeable
     170     * @throws Exception
     171     */
    141172    public static function checkCacheDir()
    142173    {
  • _plugins_/scssphp/trunk/scssphp_fonctions.php

    r115179 r115258  
    4646        if (defined('_VAR_MODE') and
    4747                (_request('var_mode') == 'css' or in_array(_VAR_MODE, array('css', 'recalcul'))) ) {
    48                 $cache_options['force_refresh'] = true;
     48                $cache_options['force_refresh'] = 'once';
    4949        }
    5050
Note: See TracChangeset for help on using the changeset viewer.