mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
feat(package): cache
This commit is contained in:
22
package/shared/resource/cache/index.ts
vendored
Normal file
22
package/shared/resource/cache/index.ts
vendored
Normal 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);
|
||||
};
|
||||
@@ -1 +1,2 @@
|
||||
export * from './version';
|
||||
export * from './cache';
|
||||
|
||||
Reference in New Issue
Block a user