MCPcopy Index your code
hub / github.com/apache/tvm / ArtifactCrossOriginStorageCache

Class ArtifactCrossOriginStorageCache

web/src/artifact_cache.ts:693–772  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

691 * Cache by cross-origin storage extension.
692 */
693export class ArtifactCrossOriginStorageCache implements ArtifactCacheTemplate {
694 private storage: CrossOriginStorage;
695
696 constructor(
697 _scope: string,
698 storage: CrossOriginStorage = new CrossOriginStorage(),
699 ) {
700 this.storage = storage;
701 }
702
703 async fetchWithCache(
704 url: string,
705 storetype?: StoreType,
706 signal?: AbortSignal,
707 ): Promise<any> {
708 const cachedResponse = await this.storage.match(url);
709 if (cachedResponse !== undefined) {
710 return this.responseToStoreType(cachedResponse, storetype);
711 }
712 await this.addToCache(url, storetype, signal);
713 const hydrated = await this.storage.match(url);
714 if (hydrated === undefined) {
715 throw new Error(`ArtifactCrossOriginStorageCache: failed to hydrate ${url}`);
716 }
717 return this.responseToStoreType(hydrated, storetype);
718 }
719
720 async addToCache(
721 url: string,
722 _storetype?: StoreType,
723 signal?: AbortSignal,
724 ): Promise<void> {
725 const existing = await this.storage.match(url);
726 if (existing !== undefined) {
727 return;
728 }
729 const request = new Request(
730 url,
731 signal ? { ...DEFAULT_FETCH_OPTIONS, signal } : DEFAULT_FETCH_OPTIONS,
732 );
733 const response = await fetch(request);
734 if (!response.ok) {
735 throw new Error(
736 `ArtifactCrossOriginStorageCache: Unable to fetch ${url}, received status ${response.status}`,
737 );
738 }
739 await this.storage.put(url, response.clone());
740 }
741
742 async hasAllKeys(keys: string[]): Promise<boolean> {
743 const results = await Promise.all(
744 keys.map(async (key) => {
745 const cached = await this.storage.match(key);
746 return cached !== undefined;
747 }),
748 );
749 return results.every((result) => result);
750 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…