Skip to content

Instantly share code, notes, and snippets.

@simonw
Created November 29, 2024 21:02
Show Gist options
  • Save simonw/3ccba6256e95b59ea6a17509855830b4 to your computer and use it in GitHub Desktop.
Save simonw/3ccba6256e95b59ea6a17509855830b4 to your computer and use it in GitHub Desktop.
async function getTotalCacheSize() {
const cacheNames = await window.caches.keys();
let totalSize = 0;
for (const cacheName of cacheNames) {
const cache = await window.caches.open(cacheName);
const keys = await cache.keys();
for (const request of keys) {
const response = await cache.match(request);
const blob = await response.blob();
totalSize += blob.size;
}
}
return (totalSize / (1024 * 1024)).toFixed(2) + ' MB';
}
// Usage
getTotalCacheSize().then(size => console.log('Total cache size:', size));
@simonw
Copy link
Author

simonw commented Nov 29, 2024

Run in Chrome to see the total cache size used by the current page. I ran this on https://huggingface.co/spaces/reach-vb/github-issue-generator-webgpu and got 924.80MB.

@simonw
Copy link
Author

simonw commented Nov 29, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment