vargai 0.4.0-alpha47 → 0.4.0-alpha48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -69,7 +69,7 @@
69
69
  "sharp": "^0.34.5",
70
70
  "zod": "^4.2.1"
71
71
  },
72
- "version": "0.4.0-alpha47",
72
+ "version": "0.4.0-alpha48",
73
73
  "exports": {
74
74
  ".": "./src/index.ts",
75
75
  "./ai": "./src/ai-sdk/index.ts",
@@ -45,28 +45,46 @@ function createMemoryCache(): CacheStorage {
45
45
  }
46
46
 
47
47
  // TODO: allow passing CacheStorage via providerOptions.fal.cacheStorage for proper serverless support
48
- function isFilesystemWritable(): boolean {
49
- try {
50
- const testPath = `.cache/.write-test-${Date.now()}`;
51
- Bun.spawnSync(["mkdir", "-p", ".cache"]);
52
- const result = Bun.spawnSync(["touch", testPath]);
53
- if (result.exitCode === 0) {
54
- Bun.spawnSync(["rm", testPath]);
55
- return true;
56
- }
57
- return false;
58
- } catch {
59
- return false;
60
- }
61
- }
62
-
63
- const USE_FILE_CACHE = isFilesystemWritable();
64
-
65
48
  function createFalCache(name: string): CacheStorage {
66
- if (!USE_FILE_CACHE) {
67
- return createMemoryCache();
68
- }
69
- return fileCache({ dir: `.cache/${name}` });
49
+ let cache: CacheStorage | null = null;
50
+ let useFallback = false;
51
+ const fallback = createMemoryCache();
52
+
53
+ const getCache = () => {
54
+ if (useFallback) return fallback;
55
+ if (!cache) cache = fileCache({ dir: `.cache/${name}` });
56
+ return cache;
57
+ };
58
+
59
+ return {
60
+ async get(key) {
61
+ if (useFallback) return fallback.get(key);
62
+ try {
63
+ return await getCache().get(key);
64
+ } catch {
65
+ useFallback = true;
66
+ return fallback.get(key);
67
+ }
68
+ },
69
+ async set(key, value, ttl) {
70
+ if (useFallback) return fallback.set(key, value, ttl);
71
+ try {
72
+ await getCache().set(key, value, ttl);
73
+ } catch {
74
+ useFallback = true;
75
+ await fallback.set(key, value, ttl);
76
+ }
77
+ },
78
+ async delete(key) {
79
+ if (useFallback) return fallback.delete(key);
80
+ try {
81
+ await getCache().delete(key);
82
+ } catch {
83
+ useFallback = true;
84
+ await fallback.delete(key);
85
+ }
86
+ },
87
+ };
70
88
  }
71
89
 
72
90
  const pendingStorage = createFalCache("fal-pending");