Skip to content

Instantly share code, notes, and snippets.

@reaktivo
Created December 2, 2019 13:29
Show Gist options
  • Save reaktivo/6d737e81dd644bf213d844d42c57602e to your computer and use it in GitHub Desktop.
Save reaktivo/6d737e81dd644bf213d844d42c57602e to your computer and use it in GitHub Desktop.
Naive cache of function with serializable arguments
export function cacheFn<T>(fn: T): T {
const cache = {};
return (...args) => {
const key = JSON.stringify(args);
return (cache[key] = cache[key] || fn(...args));
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment