From c2d4dc01b809a44511784237d634669d14d5959e Mon Sep 17 00:00:00 2001 From: LinkIsGrim Date: Mon, 5 Feb 2024 04:03:11 -0300 Subject: [PATCH 1/3] allow multiple events to clear the cache --- addons/common/functions/fnc_cachedCall.sqf | 58 ++++++++++++---------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/addons/common/functions/fnc_cachedCall.sqf b/addons/common/functions/fnc_cachedCall.sqf index 0062aec1f38..b5de134d718 100644 --- a/addons/common/functions/fnc_cachedCall.sqf +++ b/addons/common/functions/fnc_cachedCall.sqf @@ -9,7 +9,7 @@ * 2: Namespace to store the cache on * 3: Cache uid * 4: Max duration of the cache - * 5: Event that clears the cache (default: nil) + * 5: Events that clear the cache (default: nil) * * Return Value: * Result of the function @@ -20,38 +20,44 @@ * Public: No */ -params ["_params", "_function", "_namespace", "_uid", "_duration", "_event"]; +params ["_params", "_function", "_namespace", "_uid", "_duration", "_events"]; if ((_namespace getVariable [_uid, [-99999]]) select 0 < diag_tickTime) then { _namespace setVariable [_uid, [diag_tickTime + _duration, _params call _function]]; // Does the cache need to be cleared on an event? - if (!isNil "_event") then { - private _varName = format [QGVAR(clearCache_%1), _event]; - private _cacheList = missionNamespace getVariable _varName; + if (!isNil "_events") then { + if (_events isEqualType "") then { + _events = [_events]; + }; + { + private _event = _x; + private _varName = format [QGVAR(clearCache_%1), _event]; + private _cacheList = missionNamespace getVariable _varName; - // If there was no EH to clear these caches, add one - if (isNil "_cacheList") then { - _cacheList = []; - missionNamespace setVariable [_varName, _cacheList]; + // If there was no EH to clear these caches, add one + if (isNil "_cacheList") then { + _cacheList = []; + missionNamespace setVariable [_varName, _cacheList]; - [_event, { - #ifdef DEBUG_MODE_FULL - INFO_1("Clear cached variables on event: %1",_eventName); - #endif - // Get the list of caches to clear - //IGNORE_PRIVATE_WARNING ["_eventName"]; - // _eventName is defined on the function that calls the event - private _varName = format [QGVAR(clearCache_%1), _eventName]; - private _cacheList = missionNamespace getVariable [_varName, []]; - // Erase all the cached results - { - _x call FUNC(eraseCache); - } forEach _cacheList; - // Empty the list - missionNamespace setVariable [_varName, []]; - }] call CBA_fnc_addEventHandler; - }; + [_event, { + #ifdef DEBUG_MODE_FULL + INFO_1("Clear cached variables on event: %1",_eventName); + #endif + // Get the list of caches to clear + //IGNORE_PRIVATE_WARNING ["_eventName"]; + // _eventName is defined on the function that calls the event + private _varName = format [QGVAR(clearCache_%1), _eventName]; + private _cacheList = missionNamespace getVariable [_varName, []]; + // Erase all the cached results + { + _x call FUNC(eraseCache); + } forEach _cacheList; + // Empty the list + missionNamespace setVariable [_varName, []]; + }] call CBA_fnc_addEventHandler; + }; + } forEach _events; // Add this cache to the list of the event _cacheList pushBack [_namespace, _uid]; From 732196c335f56037cff2a4f2fa4008d281dfdc88 Mon Sep 17 00:00:00 2001 From: LinkIsGrim Date: Mon, 5 Feb 2024 04:08:16 -0300 Subject: [PATCH 2/3] move cacheList to proper scope --- addons/common/functions/fnc_cachedCall.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/common/functions/fnc_cachedCall.sqf b/addons/common/functions/fnc_cachedCall.sqf index b5de134d718..3fa104c68bb 100644 --- a/addons/common/functions/fnc_cachedCall.sqf +++ b/addons/common/functions/fnc_cachedCall.sqf @@ -57,10 +57,10 @@ if ((_namespace getVariable [_uid, [-99999]]) select 0 < diag_tickTime) then { missionNamespace setVariable [_varName, []]; }] call CBA_fnc_addEventHandler; }; + // Add this cache to the list of the event + _cacheList pushBack [_namespace, _uid]; } forEach _events; - // Add this cache to the list of the event - _cacheList pushBack [_namespace, _uid]; }; #ifdef DEBUG_MODE_FULL From 8e7a8060429ac2eb9c19aa4ac5bc144aca22e050 Mon Sep 17 00:00:00 2001 From: LinkIsGrim Date: Mon, 5 Feb 2024 04:09:08 -0300 Subject: [PATCH 3/3] whitespace --- addons/common/functions/fnc_cachedCall.sqf | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/common/functions/fnc_cachedCall.sqf b/addons/common/functions/fnc_cachedCall.sqf index 3fa104c68bb..dbf81b76760 100644 --- a/addons/common/functions/fnc_cachedCall.sqf +++ b/addons/common/functions/fnc_cachedCall.sqf @@ -60,7 +60,6 @@ if ((_namespace getVariable [_uid, [-99999]]) select 0 < diag_tickTime) then { // Add this cache to the list of the event _cacheList pushBack [_namespace, _uid]; } forEach _events; - }; #ifdef DEBUG_MODE_FULL