-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* caching stuff is fun Co-authored-by: Nawias <[email protected]> * asset caches kind of work? * 3ds asset file caching * more updates * we do some code cleanup?? * fix pr review comments * update some tests * update some automation, frontend code * finish up tests * not the logs! --------- Co-authored-by: Nawias <[email protected]>
- Loading branch information
Showing
22 changed files
with
1,029 additions
and
273 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import localforage from "localforage"; | ||
import { BundlerCacheItem } from "./services/types"; | ||
|
||
class Botanist { | ||
private storage: LocalForage; | ||
private isReady: boolean = false; | ||
|
||
constructor(name: string, storeName: string) { | ||
this.storage = localforage.createInstance({ | ||
name, | ||
storeName, | ||
driver: localforage.INDEXEDDB, | ||
}); | ||
} | ||
|
||
private async checkTimestamps(): Promise<void> { | ||
if (this.isReady) return; | ||
|
||
const currentTime = Date.now(); | ||
|
||
if ((await this.storage.length()) === 0) return; | ||
|
||
const keys = await this.storage.keys(); | ||
|
||
for (const key of keys) { | ||
const item: BundlerCacheItem | null = await this.storage.getItem(key); | ||
|
||
if (item !== null && item.timestamp < currentTime) { | ||
await this.storage.removeItem(key); | ||
} | ||
} | ||
|
||
this.isReady = true; | ||
} | ||
|
||
// this doesn't like any but who cares | ||
public async getItem(key: string): Promise<any | null> { | ||
if (!this.isReady) await this.checkTimestamps(); | ||
return await this.storage.getItem(key); | ||
} | ||
|
||
public async setItem(key: string, value: BundlerCacheItem): Promise<void> { | ||
await this.storage.setItem(key, value); | ||
} | ||
} | ||
|
||
export const binariesCache = new Botanist("bundler", "binaryCache"); | ||
export const assetsCache = new Botanist("bundler", "assetCache"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.