feat(package): cache

This commit is contained in:
Linden
2022-09-18 00:48:04 +10:00
parent 1dbfd01f48
commit 95dd3b1838
4 changed files with 31 additions and 1 deletions

22
package/shared/resource/cache/index.ts vendored Normal file
View File

@@ -0,0 +1,22 @@
export const cache: Record<string, any> = new Proxy(
{
resource: GetCurrentResourceName(),
},
{
get(target, key: string) {
let result = key ? target[key] : target;
if (result) return result;
AddEventHandler(`ox_lib:cache:${key}`, (value: any) => {
target[key] = value;
});
target[key] = exports.ox_lib.cache(key);
return target[key];
},
}
);
export const onCache = (key: string, cb: (value: any) => void) => {
AddEventHandler(`ox_lib:cache:${key}`, cb);
};

View File

@@ -1 +1,2 @@
export * from './version';
export * from './cache';