diff --git a/polymod/PolymodConfig.hx b/polymod/PolymodConfig.hx index e7bc5b05..f94f840e 100644 --- a/polymod/PolymodConfig.hx +++ b/polymod/PolymodConfig.hx @@ -237,4 +237,21 @@ class PolymodConfig if (caseInsensitiveZipLoading == null) caseInsensitiveZipLoading = DefineUtil.getDefineBool('POLYMOD_ZIP_INSENSITIVE', true); return caseInsensitiveZipLoading; } + + /** + * Whether the contents of text assets are cached, so that they're loaded faster. + * Don't enable this if mods need to modify these assets. + * + * Enable this option by setting the `POLYMOD_ENABLE_TEXT_CACHE` Haxe define at compile time, + * or by setting this value in your code. + * + * @default `false` + */ + public static var enableTextCache(get, default):Null; + + static function get_enableTextCache():Null + { + if (enableTextCache == null) enableTextCache = DefineUtil.getDefineBool('POLYMOD_ENABLE_TEXT_CACHE', false); + return enableTextCache; + } } diff --git a/polymod/backends/PolymodAssetLibrary.hx b/polymod/backends/PolymodAssetLibrary.hx index f251b9b3..6cc4ec39 100644 --- a/polymod/backends/PolymodAssetLibrary.hx +++ b/polymod/backends/PolymodAssetLibrary.hx @@ -182,14 +182,18 @@ class PolymodAssetLibrary public function mergeAndAppendText(id:String, modText:String):String { var cacheKey = PolymodConfig.mergeFolder + id; - if (_textCache.exists(cacheKey)) + if (PolymodConfig.enableTextCache && _textCache.exists(cacheKey)) { return _textCache.get(cacheKey); } modText = Util.mergeAndAppendText(modText, id, dirs, getTextDirectly, fileSystem, parseRules); - _textCache.set(cacheKey, modText); + if (PolymodConfig.enableTextCache) + { + _textCache.set(cacheKey, modText); + } + return modText; } @@ -247,14 +251,14 @@ class PolymodAssetLibrary public function getText(id:String):String { - if (_textCache.exists(id)) + if (PolymodConfig.enableTextCache && _textCache.exists(id)) { return _textCache.get(id); } var result = backend.getText(id); - if (result != null) + if (PolymodConfig.enableTextCache && result != null) { _textCache.set(id, result); }