mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-21 08:45:32 +03:00
Debugging cache size
This commit is contained in:
parent
5838ab6720
commit
451fc1bf52
1 changed files with 30 additions and 0 deletions
|
@ -14,6 +14,7 @@ import targetLanguages from '../data/lingva-target-languages';
|
||||||
import { api } from '../utils/api';
|
import { api } from '../utils/api';
|
||||||
import getTranslateTargetLanguage from '../utils/get-translate-target-language';
|
import getTranslateTargetLanguage from '../utils/get-translate-target-language';
|
||||||
import localeCode2Text from '../utils/localeCode2Text';
|
import localeCode2Text from '../utils/localeCode2Text';
|
||||||
|
import prettyBytes from '../utils/pretty-bytes';
|
||||||
import {
|
import {
|
||||||
initSubscription,
|
initSubscription,
|
||||||
isPushSupported,
|
isPushSupported,
|
||||||
|
@ -856,6 +857,13 @@ function Settings({ onClose }) {
|
||||||
>
|
>
|
||||||
Show keys count
|
Show keys count
|
||||||
</button>{' '}
|
</button>{' '}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="plain2 small"
|
||||||
|
onClick={async () => alert(await getCachesSize())}
|
||||||
|
>
|
||||||
|
Show cache size
|
||||||
|
</button>{' '}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="plain2 small"
|
class="plain2 small"
|
||||||
|
@ -902,6 +910,28 @@ async function getCachesKeys() {
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getCachesSize() {
|
||||||
|
const keys = await caches.keys();
|
||||||
|
let total = {};
|
||||||
|
let totalSize = 0;
|
||||||
|
for (const key of keys) {
|
||||||
|
const cache = await caches.open(key);
|
||||||
|
const k = await cache.keys();
|
||||||
|
for (const item of k) {
|
||||||
|
const response = await cache.match(item);
|
||||||
|
const blob = await response.blob();
|
||||||
|
total[key] = (total[key] || 0) + blob.size;
|
||||||
|
totalSize += blob.size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...Object.fromEntries(
|
||||||
|
Object.entries(total).map(([k, v]) => [k, prettyBytes(v)]),
|
||||||
|
),
|
||||||
|
totalSize: prettyBytes(totalSize),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function clearCacheKey(key) {
|
function clearCacheKey(key) {
|
||||||
return caches.delete(key);
|
return caches.delete(key);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue