Files
ox_lib/package/shared/resource/cache/index.ts

23 lines
563 B
TypeScript
Raw Normal View History

2022-09-18 00:48:04 +10:00
export const cache: Record<string, any> = new Proxy(
{
resource: GetCurrentResourceName(),
},
{
2023-09-16 10:37:14 +02:00
get(target: any, key: string) {
const result = key ? target[key] : target;
if (result !== undefined) return result;
2022-09-18 00:48:04 +10:00
AddEventHandler(`ox_lib:cache:${key}`, (value: any) => {
target[key] = value;
});
target[key] = exports.ox_lib.cache(key) || false;
2022-09-18 00:48:04 +10:00
return target[key];
},
}
);
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);
};