mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-04-27 11:23:02 +00:00
added tmdb response caching
This commit is contained in:
parent
e1634195be
commit
fdbfb81d25
2 changed files with 656 additions and 190 deletions
|
|
@ -90,6 +90,7 @@ const TMDBSettingsScreen = () => {
|
||||||
const [loadingLogos, setLoadingLogos] = useState(true);
|
const [loadingLogos, setLoadingLogos] = useState(true);
|
||||||
const [previewLanguage, setPreviewLanguage] = useState<string>('');
|
const [previewLanguage, setPreviewLanguage] = useState<string>('');
|
||||||
const [isPreviewFallback, setIsPreviewFallback] = useState<boolean>(false);
|
const [isPreviewFallback, setIsPreviewFallback] = useState<boolean>(false);
|
||||||
|
const [cacheSize, setCacheSize] = useState<string>('0 KB');
|
||||||
|
|
||||||
const openAlert = (
|
const openAlert = (
|
||||||
title: string,
|
title: string,
|
||||||
|
|
@ -115,11 +116,70 @@ const TMDBSettingsScreen = () => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
logger.log('[TMDBSettingsScreen] Component mounted');
|
logger.log('[TMDBSettingsScreen] Component mounted');
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
calculateCacheSize();
|
||||||
return () => {
|
return () => {
|
||||||
logger.log('[TMDBSettingsScreen] Component unmounted');
|
logger.log('[TMDBSettingsScreen] Component unmounted');
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const calculateCacheSize = async () => {
|
||||||
|
try {
|
||||||
|
const keys = await mmkvStorage.getAllKeys();
|
||||||
|
const tmdbKeys = keys.filter(key => key.startsWith('tmdb_cache_'));
|
||||||
|
|
||||||
|
let totalSize = 0;
|
||||||
|
for (const key of tmdbKeys) {
|
||||||
|
const value = mmkvStorage.getString(key);
|
||||||
|
if (value) {
|
||||||
|
totalSize += value.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert to KB/MB
|
||||||
|
let sizeStr = '';
|
||||||
|
if (totalSize < 1024) {
|
||||||
|
sizeStr = `${totalSize} B`;
|
||||||
|
} else if (totalSize < 1024 * 1024) {
|
||||||
|
sizeStr = `${(totalSize / 1024).toFixed(2)} KB`;
|
||||||
|
} else {
|
||||||
|
sizeStr = `${(totalSize / (1024 * 1024)).toFixed(2)} MB`;
|
||||||
|
}
|
||||||
|
|
||||||
|
setCacheSize(sizeStr);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('[TMDBSettingsScreen] Error calculating cache size:', error);
|
||||||
|
setCacheSize('Unknown');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClearCache = () => {
|
||||||
|
openAlert(
|
||||||
|
'Clear TMDB Cache',
|
||||||
|
`This will clear all cached TMDB data (${cacheSize}). This may temporarily slow down loading until cache rebuilds.`,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
label: 'Cancel',
|
||||||
|
onPress: () => logger.log('[TMDBSettingsScreen] Clear cache cancelled'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Clear',
|
||||||
|
onPress: async () => {
|
||||||
|
logger.log('[TMDBSettingsScreen] Proceeding with cache clear');
|
||||||
|
try {
|
||||||
|
await tmdbService.clearAllCache();
|
||||||
|
setCacheSize('0 KB');
|
||||||
|
logger.log('[TMDBSettingsScreen] Cache cleared successfully');
|
||||||
|
openAlert('Success', 'TMDB cache cleared successfully.');
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('[TMDBSettingsScreen] Failed to clear cache:', error);
|
||||||
|
openAlert('Error', 'Failed to clear cache.');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const loadSettings = async () => {
|
const loadSettings = async () => {
|
||||||
logger.log('[TMDBSettingsScreen] Loading settings from storage');
|
logger.log('[TMDBSettingsScreen] Loading settings from storage');
|
||||||
try {
|
try {
|
||||||
|
|
@ -732,6 +792,35 @@ const TMDBSettingsScreen = () => {
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Cache Management Section */}
|
||||||
|
<View style={styles.divider} />
|
||||||
|
|
||||||
|
<View style={styles.settingRow}>
|
||||||
|
<View style={styles.settingTextContainer}>
|
||||||
|
<Text style={[styles.settingTitle, { color: currentTheme.colors.text }]}>Cache Size</Text>
|
||||||
|
<Text style={[styles.settingDescription, { color: currentTheme.colors.mediumEmphasis }]}>
|
||||||
|
{cacheSize}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<TouchableOpacity
|
||||||
|
style={[styles.button, { backgroundColor: currentTheme.colors.error }]}
|
||||||
|
onPress={handleClearCache}
|
||||||
|
>
|
||||||
|
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
||||||
|
<MaterialIcons name="delete-outline" size={18} color={currentTheme.colors.white} />
|
||||||
|
<Text style={[styles.buttonText, { color: currentTheme.colors.white, marginLeft: 8 }]}>Clear Cache</Text>
|
||||||
|
</View>
|
||||||
|
</TouchableOpacity>
|
||||||
|
|
||||||
|
<View style={[styles.infoContainer, { marginTop: 12 }]}>
|
||||||
|
<MaterialIcons name="info-outline" size={18} color={currentTheme.colors.primary} />
|
||||||
|
<Text style={[styles.infoText, { color: currentTheme.colors.mediumEmphasis }]}>
|
||||||
|
TMDB responses are cached for 7 days to improve performance
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* Language Picker Modal */}
|
{/* Language Picker Modal */}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue