Affects Version/s: 6.1.X EE, 6.2.X EE, 7.0.0 M3
Branch Version/s:6.2.x, 6.1.x
Backported to Branch:Committed
Git Pull Request:
Tomcat or other application servers usually explode the resources in the web application in a temp folder, this means that the modified dates are not the original and if the server takes some milliseconds between copy .sass-cache resources and original resources the comparation fails and the css files are re-parsed.
Analyzing this feature, I noticed that .sass-cache never is being persisted when is regenerated in order to avoid new regenerations, instead of this, the filters or servlets that use this feature (currently ComboServlet, AggregateFilter, StripFilter and DynamicCSSFilter) are generating another cache level, stored in a different way depending on the filter or servlet
1. ComboServlet cache - Cache in Memory as PortalCache<String, byte>
2. AggregateFilter cache - Cache in File System with two files per data *_E_CONTENT_TYPE and *_E_DATA inside a aggregate temp folder.
3. DynamicCSSFilter cache - Cache in FS also with two files, inside a css temp folder.
4. StripFilter cache - Cache in Memory as ConcurrentLFUCache<String, String>
These filters and servlets don't ensure new parsed for the same resource because, 1 and 4 are cache in memory that is invalidate in a Server reboot or if the cache is expired (PortalCache by default is expired after 10 minutes without use)
And 2 and 3 are using the query string as part of the filename, so, if a parameter changes, eg. the browserId, the parser is executed again.
1. Resources should not be re-parsed if the plugin includes the sass-cache folder.
2. If a resource is re-parsed, this resource will never be parsed again ensuring only one ruby task per resource.
STEPS TO REPRODUCE
1.- Deploy the portlet attached
2.- Instance the portlet in a page
3.- Delete the work folder for the portlet. It should eb something like /path/to/liferay-master/tomcat-7.0.42/work/Catalina/localhost/SassTest-portlet/css/http_/SassTest-portlet/css
4.- Enable the following log traces in Control Panel. com.liferay.portal.servlet.filters.dynamiccss.DynamicCSSUtil to DEBUG
5.- Go to the temp folder in Tomcat of the deployed portlet. It should be something like /path/to/liferay-master/tomcat-7.0.42/temp/2-SassTest-portlet/css
6.- Change the date of the main.css file (touch main.css)
7.- Change the language of the portal in the URL. Something like http://localhost:8080/es_ES or http://localhost:8080/hu_HU or http://localhost:8080/nl_NL
The SASS is parsed with every request and this log trace appears
16:43:28,134 DEBUG [http-bio-8080-exec-22][DynamicCSSUtil:218] Parsing SASS for /css/main.css takes 33 ms
The SASS should not be parsed again and it should be read from the .sass-cache folder and this log trace should appear:
16:39:35,137 DEBUG [http-bio-8080-exec-55][DynamicCSSUtil:169] Loading SASS cache from /localhost/SassTest-portlet/css/.sass-cache/main.css takes 1 ms