-
Notifications
You must be signed in to change notification settings - Fork 86
Description
Linked to #256 (comment)
There is now 2 usages of the Cache in ScssPhp :
- in the Parser https://github.com/scssphp/scssphp/blob/master/src/Parser.php#L236 to get the result of an already parsed content
- in the Compiler https://github.com/scssphp/scssphp/blob/master/src/Compiler.php#L346 to get the result of an already Compiled content
For the Parser, the invalidation is straightforward: the result only rely on the content itself, and if content is unchanged it's safe to rely on the parsed result in cache.
For the Compiler, the invalidation is a bit more tricky. Even if the content of file is unchanged, the compilation result can change if one @imported file is modified, which can happen in 2 cases:
- the file that was imported in the previous compilation has changed, so it need to be re-parsed and then the whole parent file need to be compiled again
- the
@importresolving itself doesn't produce the same result (because the path changed, or because a new file is now available on the disk in a higher priority part of the path - ie overriding)
The first case is adressed by checking the timestamp of files that where used to produce the compiled cache: in the cache we are storing all imported files, and thus the Compiler can check if any of the files has been modified since the compilation result was stored in cache https://github.com/scssphp/scssphp/blob/master/src/Compiler.php#L350
The second case is not adressed at all at the moment.
A different path betwen the cached compilation result and the present call could be easy to manage (and I have to confess I didn't included that in ScssPHP because I was managing this issue in my calling function).
Checking that all @import would resolve the same way to detect the availability of a new file needs more informations to be stored in the cache:
- basically we need to register every call to
findImport()with the$urlargument and the$this->currentDirectorycontext and the result, store this list in the cache - then when checking for the validity of a cached Compile result, go through this list, and check that all the
findImport()would give the same final result - if one of the
findImport()gives a different filepath as a result OR if the timestamp changed on this file, then the cached Compile result should be ignored.
This process can be time consuming cause needing a lot of disk access, thus it should be an option for the Compiler to make a fast check (as now, only on the timestamp) or a deep check (checking all findImport())