2022-09-18 00:48:04 +10:00
|
|
|
export const cache: Record<string, any> = new Proxy(
|
|
|
|
|
{
|
|
|
|
|
resource: GetCurrentResourceName(),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
get(target, key: string) {
|
2022-09-17 20:21:06 +02:00
|
|
|
const result = key ? target[key] : target;
|
2022-09-18 22:53:04 +10:00
|
|
|
if (result !== undefined) return result;
|
2022-09-18 00:48:04 +10:00
|
|
|
|
|
|
|
|
AddEventHandler(`ox_lib:cache:${key}`, (value: any) => {
|
|
|
|
|
target[key] = value;
|
|
|
|
|
});
|
|
|
|
|
|
2022-09-18 22:53:04 +10:00
|
|
|
target[key] = exports.ox_lib.cache(key) || false;
|
2022-09-18 00:48:04 +10:00
|
|
|
return target[key];
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2022-09-17 20:21:06 +02:00
|
|
|
export const onCache = <T = any>(key: string, cb: (value: T) => void) => {
|
2022-09-18 00:48:04 +10:00
|
|
|
AddEventHandler(`ox_lib:cache:${key}`, cb);
|
|
|
|
|
};
|