wikimedia / less.php

Less.js ported to PHP. Mirrored from https://gerrit.wikimedia.org/g/mediawiki/libs/less.php/
Apache License 2.0
111 stars 195 forks source link

Source code question. Cache::get() what are list files for? #79

Closed AndryG closed 1 year ago

AndryG commented 2 years ago

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

Krinkle commented 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: