We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
clearApiCache
1 parent 02bca04 commit f4bf6c9Copy full SHA for f4bf6c9
src/lib/py/api.ts
@@ -1,17 +1,20 @@
1
+import type { PyCallable, PyProxy } from "pyodide/ffi";
2
+
3
import { py } from "./load";
4
-const cache = new Map<string, any>();
5
+const cache = new Map<string, PyProxy>();
6
7
export function getApi<T = () => any>(slug: string): T {
8
if (cache.has(slug)) {
9
return cache.get(slug) as T;
10
} else {
- const api = py.pyimport(slug) as T;
11
+ const api = py.pyimport(slug) as T & PyCallable;
12
cache.set(slug, api);
13
return api;
14
}
15
16
17
export function clearApiCache() {
18
+ cache.forEach(value => value.destroy());
19
cache.clear();
20
0 commit comments