mirror of
https://github.com/Nezumi-2711/cloudflare-gateway-pihole-scripts.git
synced 2026-09-22 13:38:37 +00:00
implement memoization for domain normalization
This commit is contained in:
@@ -90,3 +90,24 @@ export const readFile = async (filePath, onLine) => {
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Memoizes a function
|
||||
* @template T The argument type of the function.
|
||||
* @template R The return type of the function.
|
||||
* @param {(...fnArgs: T[]) => R} fn The function to be memoized.
|
||||
*/
|
||||
export const memoize = (fn) => {
|
||||
const cache = new Map();
|
||||
|
||||
return (...args) => {
|
||||
const key = args.join("-");
|
||||
|
||||
if (cache.has(key)) return cache.get(key);
|
||||
|
||||
const result = fn(...args);
|
||||
|
||||
cache.set(key, result);
|
||||
return result;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user