mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
feat(package): cache
This commit is contained in:
@@ -1,4 +1,9 @@
|
|||||||
import * as lib from './resource';
|
import * as lib from './resource';
|
||||||
export * from './resource';
|
import { cache, onCache } from '../shared/resource';
|
||||||
|
|
||||||
|
cache.playerId = PlayerId();
|
||||||
|
cache.serverId = GetPlayerServerId(cache.playerId);
|
||||||
|
|
||||||
|
export { cache, onCache };
|
||||||
|
export * from './resource';
|
||||||
export default lib;
|
export default lib;
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import * as lib from './resource';
|
import * as lib from './resource';
|
||||||
|
import { cache, onCache } from '../shared/resource';
|
||||||
export * from './resource';
|
export * from './resource';
|
||||||
|
|
||||||
export default lib;
|
export default lib;
|
||||||
|
export { cache, onCache };
|
||||||
|
|||||||
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 './version';
|
||||||
|
export * from './cache';
|
||||||
|
|||||||
Reference in New Issue
Block a user