Common - Allow multiple events to clear a cached call (#9770)

This commit is contained in:
Grim 2024-02-11 22:13:37 -03:00 committed by GitHub
parent 1e1d1d63f2
commit d6eb6b981c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,7 +9,7 @@
* 2: Namespace to store the cache on <NAMESPACE>
* 3: Cache uid <STRING>
* 4: Max duration of the cache <NUMBER>
* 5: Event that clears the cache (default: nil) <STRING>
* 5: Events that clear the cache (default: nil) <STRING or ARRAY of STRING>
*
* Return Value:
* Result of the function <ANY>
@ -20,13 +20,18 @@
* 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 {
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;
@ -52,9 +57,9 @@ 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;
};
#ifdef DEBUG_MODE_FULL