From b08e2c4912f312f7fc92f1215dec85f1fcc11e97 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sat, 30 Jul 2016 15:06:50 +1000 Subject: [PATCH] Introduce deep hashing on asset combiner Added cms.enableAssetDeepHashing config item, disabled by default Recompile assets Refs #2248 Refs https://github.com/octobercms/library/pull/225 --- config/cms.php | 14 ++++++ modules/system/assets/js/lang/lang.el.js | 2 +- modules/system/classes/CombineAssets.php | 64 +++++++++++++++++++++++- 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/config/cms.php b/config/cms.php index 1b3e01dee..7c494e203 100644 --- a/config/cms.php +++ b/config/cms.php @@ -166,6 +166,20 @@ return [ 'enableAssetMinify' => null, + /* + |-------------------------------------------------------------------------- + | Check import timestamps when combining assets + |-------------------------------------------------------------------------- + | + | If deep hashing is enabled, the combiner cache will be reset when a change + | is detected on imported files, in addition to those referenced directly. + | This will cause slower page performance. If set to null, assets are + | minified, when debug mode (app.debug) is disabled. + | + */ + + 'enableAssetDeepHashing' => false, + /* |-------------------------------------------------------------------------- | Public plugins path diff --git a/modules/system/assets/js/lang/lang.el.js b/modules/system/assets/js/lang/lang.el.js index 1ff79e946..843f4f5bb 100644 --- a/modules/system/assets/js/lang/lang.el.js +++ b/modules/system/assets/js/lang/lang.el.js @@ -5,7 +5,7 @@ if ($.oc === undefined) $.oc = {} if ($.oc.langMessages === undefined) $.oc.langMessages = {} $.oc.langMessages['el'] = $.extend( $.oc.langMessages['el'] || {}, - {"markdowneditor":{"formatting":"\u039c\u03bf\u03c1\u03c6\u03bf\u03c0\u03bf\u03af\u03b7\u03c3\u03b7","quote":"\u03a0\u03b1\u03c1\u03ac\u03b8\u03b5\u03c3\u03b7","code":"\u039a\u03ce\u03b4\u03b9\u03ba\u03b1\u03c2","header1":"\u039a\u03b5\u03c6\u03b1\u03bb\u03af\u03b4\u03b1 1","header2":"\u039a\u03b5\u03c6\u03b1\u03bb\u03af\u03b4\u03b1 2","header3":"\u039a\u03b5\u03c6\u03b1\u03bb\u03af\u03b4\u03b1 3","header4":"\u039a\u03b5\u03c6\u03b1\u03bb\u03af\u03b4\u03b1 4","header5":"\u039a\u03b5\u03c6\u03b1\u03bb\u03af\u03b4\u03b1 5","header6":"\u039a\u03b5\u03c6\u03b1\u03bb\u03af\u03b4\u03b1 6","bold":"\u0388\u03bd\u03c4\u03bf\u03bd\u03b1","italic":"\u0399\u03c4\u03b1\u03bb\u03b9\u03ba\u03ac","unorderedlist":"\u039c\u03b7 \u03c4\u03b1\u03be\u03b9\u03bd\u03bf\u03bc\u03b7\u03bc\u03ad\u03bd\u03b7 \u03bb\u03af\u03c3\u03c4\u03b1","orderedlist":"\u03a4\u03b1\u03be\u03b9\u03bd\u03bf\u03bc\u03b7\u03bc\u03ad\u03bd\u03b7 \u03bb\u03af\u03c3\u03c4\u03b1","video":"\u0392\u03af\u03bd\u03c4\u03b5\u03bf","image":"\u0395\u03b9\u03ba\u03cc\u03bd\u03b1","link":"\u03a3\u03cd\u03bd\u03b4\u03b5\u03c3\u03bc\u03bf\u03c2","horizontalrule":"\u0395\u03b9\u03c3\u03b1\u03b3\u03c9\u03b3\u03ae \u039f\u03c1\u03b9\u03b6\u03cc\u03bd\u03c4\u03b9\u03b1\u03c2 \u0393\u03c1\u03b1\u03bc\u03bc\u03ae\u03c2","fullscreen":"\u03a0\u03bb\u03ae\u03c1\u03b7\u03c2 \u03bf\u03b8\u03cc\u03bd\u03b7","preview":"\u03a0\u03c1\u03bf\u03b5\u03c0\u03b9\u03c3\u03ba\u03cc\u03c0\u03b7\u03c3\u03b7"},"mediamanager":{"insert_link":"\u0395\u03b9\u03c3\u03b1\u03b3\u03c9\u03b3\u03ae \u03a3\u03c5\u03bd\u03b4\u03ad\u03c3\u03bc\u03bf\u03c5 \u03b1\u03c0\u03cc \u03c4\u03b1 \u039c\u03ad\u03c3\u03b1","insert_image":"\u0395\u03b9\u03c3\u03b1\u03b3\u03c9\u03b3\u03ae \u0395\u03b9\u03ba\u03cc\u03bd\u03b1\u03c2 \u03b1\u03c0\u03cc \u03c4\u03b1 \u039c\u03ad\u03c3\u03b1","insert_video":"\u0395\u03b9\u03c3\u03b1\u03b3\u03c9\u03b3\u03ae \u0392\u03af\u03bd\u03c4\u03b5\u03bf \u03b1\u03c0\u03cc \u03c4\u03b1 \u039c\u03ad\u03c3\u03b1","insert_audio":"\u0395\u03b9\u03c3\u03b1\u03b3\u03c9\u03b3\u03ae \u0389\u03c7\u03bf\u03c5 \u03b1\u03c0\u03cc \u03c4\u03b1 \u039c\u03ad\u03c3\u03b1","invalid_file_empty_insert":"\u03a0\u03b1\u03c1\u03b1\u03ba\u03b1\u03bb\u03bf\u03cd\u03bc\u03b5 \u03b5\u03c0\u03b9\u03bb\u03ad\u03be\u03c4\u03b5 \u03ad\u03bd\u03b1 \u03b1\u03c1\u03c7\u03b5\u03af\u03bf \u03b3\u03b9\u03b1 \u03bd\u03b1 \u03b5\u03b9\u03c3\u03ac\u03b3\u03b5\u03c4\u03b5 \u03c3\u03c5\u03bd\u03b4\u03ad\u03c3\u03bc\u03bf\u03c5\u03c2 \u03c3\u03b5 \u03b1\u03c5\u03c4\u03cc.","invalid_file_single_insert":"\u03a0\u03b1\u03c1\u03b1\u03ba\u03b1\u03bb\u03bf\u03cd\u03bc\u03b5 \u03b5\u03c0\u03b9\u03bb\u03ad\u03be\u03c4\u03b5 \u03ad\u03bd\u03b1 \u03bc\u03bf\u03bd\u03b1\u03b4\u03b9\u03ba\u03cc \u03b1\u03c1\u03c7\u03b5\u03af\u03bf.","invalid_image_empty_insert":"\u03a0\u03b1\u03c1\u03b1\u03ba\u03b1\u03bb\u03bf\u03cd\u03bc\u03b5 \u03b5\u03c0\u03b9\u03bb\u03ad\u03be\u03c4\u03b5 \u03c4\u03b7\u03bd \u03b5\u03b9\u03ba\u03cc\u03bd\u03b1 \u03ae \u03c4\u03b9\u03c2 \u03b5\u03b9\u03ba\u03cc\u03bd\u03b5\u03c2 \u03b3\u03b9\u03b1 \u03b5\u03b9\u03c3\u03b1\u03b3\u03c9\u03b3\u03b7.","invalid_video_empty_insert":"\u03a0\u03b1\u03c1\u03b1\u03ba\u03b1\u03bb\u03bf\u03cd\u03bc\u03b5 \u03b5\u03c0\u03b9\u03bb\u03ad\u03be\u03c4\u03b5 \u03ad\u03bd\u03b1 \u03b1\u03c1\u03c7\u03b5\u03af\u03bf \u03b2\u03af\u03bd\u03c4\u03b5\u03bf \u03b3\u03b9\u03b1 \u03b5\u03b9\u03c3\u03b1\u03b3\u03c9\u03b3\u03ae.","invalid_audio_empty_insert":"\u03a0\u03b1\u03c1\u03b1\u03ba\u03b1\u03bb\u03bf\u03cd\u03bc\u03b5 \u03b5\u03c0\u03b9\u03bb\u03ad\u03be\u03c4\u03b5 \u03ad\u03bd\u03b1 \u03b1\u03c1\u03c7\u03b5\u03af\u03bf \u03ae\u03c7\u03bf\u03c5 \u03b3\u03b9\u03b1 \u03b5\u03b9\u03c3\u03b1\u03b3\u03c9\u03b3\u03ae."},"alert":{"confirm_button_text":"\u0395\u03bd\u03c4\u03ac\u03be\u03b5\u03b9","cancel_button_text":"\u0386\u03ba\u03c5\u03c1\u03bf"},"datepicker":{"previousMonth":"Previous Month","nextMonth":"Next Month","months":["January","February","March","April","May","June","July","August","September","October","November","December"],"weekdays":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"weekdaysShort":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]},"filter":{"group":{"all":"all"},"dates":{"all":"all","filter_button_text":"Filter","reset_button_text":"Reset","date_placeholder":"Date","after_placeholder":"After","before_placeholder":"Before"}},"eventlog":{"show_stacktrace":"Show the stacktrace","hide_stacktrace":"Hide the stacktrace","tabs":{"formatted":"Formatted","raw":"Raw"},"editor":{"title":"Source code editor","description":"Your operating system should be configured to listen to one of these URL schemes.","openWith":"Open with","remember_choice":"Remember selected option for this session","open":"Open","cancel":"Cancel"}}} + {"markdowneditor":{"formatting":"\u039c\u03bf\u03c1\u03c6\u03bf\u03c0\u03bf\u03af\u03b7\u03c3\u03b7","quote":"\u03a0\u03b1\u03c1\u03ac\u03b8\u03b5\u03c3\u03b7","code":"\u039a\u03ce\u03b4\u03b9\u03ba\u03b1\u03c2","header1":"\u039a\u03b5\u03c6\u03b1\u03bb\u03af\u03b4\u03b1 1","header2":"\u039a\u03b5\u03c6\u03b1\u03bb\u03af\u03b4\u03b1 2","header3":"\u039a\u03b5\u03c6\u03b1\u03bb\u03af\u03b4\u03b1 3","header4":"\u039a\u03b5\u03c6\u03b1\u03bb\u03af\u03b4\u03b1 4","header5":"\u039a\u03b5\u03c6\u03b1\u03bb\u03af\u03b4\u03b1 5","header6":"\u039a\u03b5\u03c6\u03b1\u03bb\u03af\u03b4\u03b1 6","bold":"\u0388\u03bd\u03c4\u03bf\u03bd\u03b1","italic":"\u0399\u03c4\u03b1\u03bb\u03b9\u03ba\u03ac","unorderedlist":"\u039c\u03b7 \u03c4\u03b1\u03be\u03b9\u03bd\u03bf\u03bc\u03b7\u03bc\u03ad\u03bd\u03b7 \u03bb\u03af\u03c3\u03c4\u03b1","orderedlist":"\u03a4\u03b1\u03be\u03b9\u03bd\u03bf\u03bc\u03b7\u03bc\u03ad\u03bd\u03b7 \u03bb\u03af\u03c3\u03c4\u03b1","video":"\u0392\u03af\u03bd\u03c4\u03b5\u03bf","image":"\u0395\u03b9\u03ba\u03cc\u03bd\u03b1","link":"\u03a3\u03cd\u03bd\u03b4\u03b5\u03c3\u03bc\u03bf\u03c2","horizontalrule":"\u0395\u03b9\u03c3\u03b1\u03b3\u03c9\u03b3\u03ae \u039f\u03c1\u03b9\u03b6\u03cc\u03bd\u03c4\u03b9\u03b1\u03c2 \u0393\u03c1\u03b1\u03bc\u03bc\u03ae\u03c2","fullscreen":"\u03a0\u03bb\u03ae\u03c1\u03b7\u03c2 \u03bf\u03b8\u03cc\u03bd\u03b7","preview":"\u03a0\u03c1\u03bf\u03b5\u03c0\u03b9\u03c3\u03ba\u03cc\u03c0\u03b7\u03c3\u03b7"},"mediamanager":{"insert_link":"\u0395\u03b9\u03c3\u03b1\u03b3\u03c9\u03b3\u03ae \u03a3\u03c5\u03bd\u03b4\u03ad\u03c3\u03bc\u03bf\u03c5 \u03b1\u03c0\u03cc \u03c4\u03b1 \u039c\u03ad\u03c3\u03b1","insert_image":"\u0395\u03b9\u03c3\u03b1\u03b3\u03c9\u03b3\u03ae \u0395\u03b9\u03ba\u03cc\u03bd\u03b1\u03c2 \u03b1\u03c0\u03cc \u03c4\u03b1 \u039c\u03ad\u03c3\u03b1","insert_video":"\u0395\u03b9\u03c3\u03b1\u03b3\u03c9\u03b3\u03ae \u0392\u03af\u03bd\u03c4\u03b5\u03bf \u03b1\u03c0\u03cc \u03c4\u03b1 \u039c\u03ad\u03c3\u03b1","insert_audio":"\u0395\u03b9\u03c3\u03b1\u03b3\u03c9\u03b3\u03ae \u0389\u03c7\u03bf\u03c5 \u03b1\u03c0\u03cc \u03c4\u03b1 \u039c\u03ad\u03c3\u03b1","invalid_file_empty_insert":"\u03a0\u03b1\u03c1\u03b1\u03ba\u03b1\u03bb\u03bf\u03cd\u03bc\u03b5 \u03b5\u03c0\u03b9\u03bb\u03ad\u03be\u03c4\u03b5 \u03ad\u03bd\u03b1 \u03b1\u03c1\u03c7\u03b5\u03af\u03bf \u03b3\u03b9\u03b1 \u03bd\u03b1 \u03b5\u03b9\u03c3\u03ac\u03b3\u03b5\u03c4\u03b5 \u03c3\u03c5\u03bd\u03b4\u03ad\u03c3\u03bc\u03bf\u03c5\u03c2 \u03c3\u03b5 \u03b1\u03c5\u03c4\u03cc.","invalid_file_single_insert":"\u03a0\u03b1\u03c1\u03b1\u03ba\u03b1\u03bb\u03bf\u03cd\u03bc\u03b5 \u03b5\u03c0\u03b9\u03bb\u03ad\u03be\u03c4\u03b5 \u03ad\u03bd\u03b1 \u03bc\u03bf\u03bd\u03b1\u03b4\u03b9\u03ba\u03cc \u03b1\u03c1\u03c7\u03b5\u03af\u03bf.","invalid_image_empty_insert":"\u03a0\u03b1\u03c1\u03b1\u03ba\u03b1\u03bb\u03bf\u03cd\u03bc\u03b5 \u03b5\u03c0\u03b9\u03bb\u03ad\u03be\u03c4\u03b5 \u03c4\u03b7\u03bd \u03b5\u03b9\u03ba\u03cc\u03bd\u03b1 \u03ae \u03c4\u03b9\u03c2 \u03b5\u03b9\u03ba\u03cc\u03bd\u03b5\u03c2 \u03b3\u03b9\u03b1 \u03b5\u03b9\u03c3\u03b1\u03b3\u03c9\u03b3\u03b7.","invalid_video_empty_insert":"\u03a0\u03b1\u03c1\u03b1\u03ba\u03b1\u03bb\u03bf\u03cd\u03bc\u03b5 \u03b5\u03c0\u03b9\u03bb\u03ad\u03be\u03c4\u03b5 \u03ad\u03bd\u03b1 \u03b1\u03c1\u03c7\u03b5\u03af\u03bf \u03b2\u03af\u03bd\u03c4\u03b5\u03bf \u03b3\u03b9\u03b1 \u03b5\u03b9\u03c3\u03b1\u03b3\u03c9\u03b3\u03ae.","invalid_audio_empty_insert":"\u03a0\u03b1\u03c1\u03b1\u03ba\u03b1\u03bb\u03bf\u03cd\u03bc\u03b5 \u03b5\u03c0\u03b9\u03bb\u03ad\u03be\u03c4\u03b5 \u03ad\u03bd\u03b1 \u03b1\u03c1\u03c7\u03b5\u03af\u03bf \u03ae\u03c7\u03bf\u03c5 \u03b3\u03b9\u03b1 \u03b5\u03b9\u03c3\u03b1\u03b3\u03c9\u03b3\u03ae."},"alert":{"confirm_button_text":"\u0395\u03bd\u03c4\u03ac\u03be\u03b5\u03b9","cancel_button_text":"\u0386\u03ba\u03c5\u03c1\u03bf"},"datepicker":{"previousMonth":"\u03a0\u03c1\u03bf\u03b7\u03b3\u03bf\u03cd\u03bc\u03b5\u03bd\u03bf\u03c2 \u039c\u03ae\u03bd\u03b1\u03c2","nextMonth":"\u0395\u03c0\u03cc\u03bc\u03b5\u03bd\u03bf\u03c2 \u039c\u03ae\u03bd\u03b1\u03c2","months":["\u0399\u03b1\u03bd\u03bf\u03c5\u03ac\u03c1\u03b9\u03bf\u03c2","\u03a6\u03b5\u03b2\u03c1\u03bf\u03c5\u03ac\u03c1\u03b9\u03bf\u03c2","\u039c\u03ac\u03c1\u03c4\u03b9\u03bf\u03c2","\u0391\u03c0\u03c1\u03af\u03bb\u03b9\u03bf\u03c2","\u039c\u03ac\u03b9\u03bf\u03c2","\u0399\u03bf\u03cd\u03bd\u03b9\u03bf\u03c2","\u0399\u03bf\u03cd\u03bb\u03b9\u03bf\u03c2","\u0391\u03cd\u03b3\u03bf\u03c5\u03c3\u03c4\u03bf\u03c2","\u03a3\u03b5\u03c0\u03c4\u03ad\u03bc\u03b2\u03c1\u03b9\u03bf\u03c2","\u039f\u03ba\u03c4\u03ce\u03b2\u03c1\u03b9\u03bf\u03c2","\u039d\u03bf\u03ad\u03bc\u03b2\u03c1\u03b9\u03bf\u03c2","\u0394\u03b5\u03ba\u03ad\u03bc\u03b2\u03c1\u03b9\u03bf\u03c2"],"weekdays":["\u039a\u03c5\u03c1\u03b9\u03b1\u03ba\u03ae","\u0394\u03b5\u03c5\u03c4\u03ad\u03c1\u03b1","\u03a4\u03c1\u03af\u03c4\u03b7","\u03a4\u03b5\u03c4\u03ac\u03c1\u03c4\u03b7","\u03a0\u03ad\u03bc\u03c0\u03c4\u03b7","\u03a0\u03b1\u03c1\u03b1\u03c3\u03ba\u03b5\u03c5\u03ae","\u03a3\u03ac\u03b2\u03b2\u03b1\u03c4\u03bf"],"weekdaysShort":["\u039a\u03c5\u03c1","\u0394\u03b5\u03c5","\u03a4\u03c1\u03b9","\u03a4\u03b5\u03c4","\u03a0\u03b5\u03bc","\u03a0\u03b1\u03c1","\u03a3\u03b1\u03b2"]},"filter":{"group":{"all":"\u03cc\u03bb\u03b1"},"dates":{"all":"\u03cc\u03bb\u03b1","filter_button_text":"\u03a6\u03af\u03bb\u03c4\u03c1\u03bf","reset_button_text":"\u0395\u03c0\u03b1\u03bd\u03b1\u03c6\u03bf\u03c1\u03ac","date_placeholder":"\u0397\u03bc\u03b5\u03c1\u03bf\u03bc\u03b7\u03bd\u03af\u03b1","after_placeholder":"\u039c\u03b5\u03c4\u03ac","before_placeholder":"\u03a0\u03c1\u03af\u03bd"}},"eventlog":{"show_stacktrace":"\u0395\u03bc\u03c6\u03ac\u03bd\u03b9\u03c3\u03b7 stacktrace","hide_stacktrace":"\u0391\u03c0\u03cc\u03ba\u03c1\u03c5\u03c8\u03b7 stachtrace","tabs":{"formatted":"\u039c\u03bf\u03c1\u03c6\u03bf\u03c0\u03bf\u03b9\u03b7\u03bc\u03ad\u03bd\u03bf","raw":"\u0391\u03ba\u03b1\u03c4\u03ad\u03c1\u03b3\u03b1\u03c3\u03c4\u03bf"},"editor":{"title":"\u0395\u03c0\u03b5\u03be\u03b5\u03c1\u03b3\u03b1\u03c3\u03c4\u03ae\u03c2 \u03c0\u03b7\u03b3\u03b1\u03af\u03bf\u03c5 \u03ba\u03ce\u03b4\u03b9\u03ba\u03b1","description":"\u03a4\u03bf \u03bb\u03b5\u03b9\u03c4\u03bf\u03c5\u03c1\u03b3\u03b9\u03ba\u03cc \u03c3\u03bf\u03c5 \u03c3\u03cd\u03c3\u03c4\u03b7\u03bc\u03b1 \u03b8\u03b1 \u03c0\u03c1\u03ad\u03c0\u03b5\u03b9 \u03bd\u03b1 \u03c1\u03c5\u03b8\u03bc\u03b9\u03c3\u03c4\u03b5\u03af \u03b3\u03b9\u03b1 \u03bd\u03b1 \u03b1\u03bd\u03c4\u03b1\u03c0\u03bf\u03ba\u03c1\u03af\u03bd\u03b5\u03c4\u03b1\u03b9 \u03c3\u03b5 \u03bc\u03af\u03b1 \u03b1\u03c0\u03cc \u03c4\u03b9\u03c2 \u03b1\u03ba\u03cc\u03bb\u03bf\u03c5\u03b8\u03b5\u03c2 URL \u03b1\u03c0\u03b5\u03b9\u03ba\u03bf\u03bd\u03af\u03c3\u03b5\u03b9\u03c2.","openWith":"\u0386\u03bd\u03bf\u03b9\u03b3\u03bc\u03b1 \u03bc\u03b5","remember_choice":"\u0391\u03c0\u03bf\u03bc\u03bd\u03b7\u03bc\u03cc\u03bd\u03b5\u03c5\u03c3\u03b7 \u03b1\u03c5\u03c4\u03ae\u03c2 \u03c4\u03b7\u03c2 \u03b5\u03c0\u03b9\u03bb\u03bf\u03b3\u03ae\u03c2 \u03b3\u03b9\u03b1 \u03b1\u03c5\u03c4\u03ae\u03bd \u03c4\u03b7\u03bd \u03c0\u03b5\u03c1\u03af\u03bf\u03b4\u03bf \u03bb\u03b5\u03b9\u03c4\u03bf\u03c5\u03c1\u03b3\u03af\u03b1\u03c2","open":"\u0386\u03bd\u03bf\u03b9\u03b3\u03bc\u03b1","cancel":"\u0386\u03ba\u03c5\u03c1\u03bf"}}} ); //! moment.js locale configuration diff --git a/modules/system/classes/CombineAssets.php b/modules/system/classes/CombineAssets.php index 19b9c4a30..67d1868bf 100644 --- a/modules/system/classes/CombineAssets.php +++ b/modules/system/classes/CombineAssets.php @@ -14,6 +14,7 @@ use Assetic\Asset\FileAsset; use Assetic\Asset\GlobAsset; use Assetic\Asset\AssetCache; use Assetic\Asset\AssetCollection; +use Assetic\Factory\AssetFactory; use October\Rain\Parse\Assetic\FilesystemCache; use System\Helpers\Cache as CacheHelper; use ApplicationException; @@ -75,6 +76,12 @@ class CombineAssets */ public $useMinify = false; + /** + * @var bool When true, cache will be busted when an import is modified. + * Enabling this feature will make page loading slower. + */ + public $useDeepHashing = false; + /** * @var array Cache of registration callbacks. */ @@ -90,11 +97,16 @@ class CombineAssets */ $this->useCache = Config::get('cms.enableAssetCache', false); $this->useMinify = Config::get('cms.enableAssetMinify', null); + $this->useDeepHashing = Config::get('cms.enableAssetDeepHashing', null); if ($this->useMinify === null) { $this->useMinify = !Config::get('app.debug', false); } + if ($this->useDeepHashing === null) { + $this->useDeepHashing = Config::get('app.debug', false); + } + /* * Register JavaScript filters */ @@ -176,6 +188,8 @@ class CombineAssets $this->localPath = $cacheInfo['path']; $this->storagePath = storage_path('cms/combiner/assets'); + $this->setHashOnCombinerFilters($cacheKey); + $combiner = $this->prepareCombiner($cacheInfo['files']); $contents = $combiner->dump(); $mime = ($cacheInfo['extension'] == 'css') ? 'text/css' : 'application/javascript'; @@ -292,8 +306,11 @@ class CombineAssets $cacheInfo = $this->useCache ? $this->getCache($cacheKey) : false; if (!$cacheInfo) { + $this->setHashOnCombinerFilters($cacheKey); + $combiner = $this->prepareCombiner($assets); - $lastMod = $combiner->getLastModified(); + $factory = new AssetFactory($this->localPath); + $lastMod = $factory->getLastModified($combiner); $cacheInfo = [ 'version' => $cacheKey.'-'.$lastMod, @@ -354,6 +371,44 @@ class CombineAssets return $cachedCollection; } + /** + * Busts the cache based on a different cache key. + * @return void + */ + protected function setHashOnCombinerFilters($hash) + { + $allFilters = call_user_func_array('array_merge', $this->getFilters()); + + foreach ($allFilters as $filter) { + if (method_exists($filter, 'setHash')) { + $filter->setHash($hash); + } + } + } + + /** + * Returns a deep hash on filters that support it. + * @return void + */ + protected function getDeepHashFromAssets($assets) + { + $key = ''; + + $allFilters = call_user_func_array('array_merge', $this->getFilters()); + + $assetFiles = array_map(function($file) { + return $this->localPath.'/'.$file; + }, $assets); + + foreach ($allFilters as $filter) { + if (method_exists($filter, 'hashFromAssets')) { + $key .= $filter->hashFromAssets($assetFiles, $this->localPath); + } + } + + return $key; + } + /** * Returns the URL used for accessing the combined files. * @param string $outputFilename A custom file name to use. @@ -663,6 +718,13 @@ class CombineAssets { $cacheKey = $this->localPath . implode('|', $assets); + /* + * Deep hashing + */ + if ($this->useDeepHashing) { + $cacheKey .= $this->getDeepHashFromAssets($assets); + } + /* * Extensibility */