Closed AndryG closed 1 year ago
@AndryG If I understand your question correctly, I think you're asking why the cache filename is different depending on which other files are included by your LESS file. The reason for this is that the Cache class intends to give you a guruantee that the cache is up-to-date with the current contents. This is different from a time-based cache (e.g. with expiry times or TTL time-to-live values). The output of main.less
varies not only by the hash of this file, but also by the hash of any other files that it imports via @import
.
Having said that, I do find Less_Cache
fairly complex, and in a high-traffic production environment, I would not recommend its use. Instead, you can use the $parser->allParsedFiles()
method to make something simpler and more performant based on an in-memory cache such as Memcached. I would actually recommend using php-apcu if you can as that will perform even better by fetching it from the server process.
For an example of using less.php in this way, refer to how we use less.php in Wikipedia's MediaWiki source at https://github.com/wikimedia/mediawiki/blob/1.39.1/includes/ResourceLoader/FileModule.php#L1107-L1144.
It works like this:
.less
file content, and build a cache key of (less content, import dirs, variables)
.$data
as follows:
$data['files']
and check that the file hashes are still the same (we use another layer of php-apcu caching for the file hashes here based on mtimes for improved performance).$data['css']
.$data
is stored as follows:
$parser->parse( $lessContent, $lessFile )->getCss();
$parser->AllParsedFiles();
hash( map( $files, hash ) )
$data['css']
Source code question. What are $list_files for? It is possible to calculate $compiled_name from $less_files and check its presence. What is the file list for?
I want to reduce disk access. If these lists are really needed, then make friends with memcached through cache_method