update image caching

This commit is contained in:
tapframe 2025-10-09 12:40:19 +05:30
parent f146f6a312
commit 230afd7414
6 changed files with 21 additions and 10 deletions

View file

@ -60,7 +60,7 @@ const OptimizedImage: React.FC<OptimizedImageProps> = ({
onError,
contentFit = 'cover',
transition = 200,
cachePolicy = 'memory-disk'
cachePolicy = 'memory'
}) => {
const [isLoaded, setIsLoaded] = useState(false);
const [hasError, setHasError] = useState(false);

View file

@ -258,7 +258,7 @@ const ContentItem = ({ item, onPress, shouldLoadImage: shouldLoadImageProp, defe
source={{ uri: optimizedPosterUrl }}
style={[styles.poster, { backgroundColor: currentTheme.colors.elevation1, borderRadius: posterRadius }]}
contentFit="cover"
cachePolicy={Platform.OS === 'android' ? 'disk' : 'memory-disk'}
cachePolicy="memory"
transition={0}
allowDownscaling
priority="normal" // Normal priority for horizontal scrolling

View file

@ -165,7 +165,7 @@ const HeroCarousel: React.FC<HeroCarouselProps> = ({ items, loading = false }) =
style={styles.backgroundImage as ImageStyle}
contentFit="cover"
blurRadius={Platform.OS === 'android' ? 8 : 12}
cachePolicy="memory-disk"
cachePolicy="memory"
transition={0}
priority="low"
/>
@ -191,7 +191,7 @@ const HeroCarousel: React.FC<HeroCarouselProps> = ({ items, loading = false }) =
source={{ uri: data[activeIndex + 1].banner || data[activeIndex + 1].poster }}
style={{ width: 1, height: 1 }}
contentFit="cover"
cachePolicy="memory-disk"
cachePolicy="memory"
transition={0}
/>
)}
@ -200,7 +200,7 @@ const HeroCarousel: React.FC<HeroCarouselProps> = ({ items, loading = false }) =
source={{ uri: data[activeIndex - 1].banner || data[activeIndex - 1].poster }}
style={{ width: 1, height: 1 }}
contentFit="cover"
cachePolicy="memory-disk"
cachePolicy="memory"
transition={0}
/>
)}
@ -285,7 +285,7 @@ const CarouselCard: React.FC<CarouselCardProps> = memo(({ item, colors, logoFail
style={styles.banner as ImageStyle}
contentFit="cover"
transition={0}
cachePolicy="memory-disk"
cachePolicy="memory"
/>
<LinearGradient
colors={["transparent", "rgba(0,0,0,0.2)", "rgba(0,0,0,0.6)"]}
@ -300,7 +300,7 @@ const CarouselCard: React.FC<CarouselCardProps> = memo(({ item, colors, logoFail
style={styles.logo as ImageStyle}
contentFit="contain"
transition={0}
cachePolicy="memory-disk"
cachePolicy="memory"
onError={onLogoError}
/>
) : (

View file

@ -403,11 +403,12 @@ const LibraryScreen = () => {
>
<View>
<View style={[styles.posterContainer, { shadowColor: currentTheme.colors.black }]}>
<Image
<Image
source={{ uri: item.poster || 'https://via.placeholder.com/300x450' }}
style={styles.poster}
contentFit="cover"
transition={300}
cachePolicy="memory"
transition={300}
/>
{item.watched && (
<View style={styles.watchedIndicator}>

View file

@ -199,6 +199,8 @@ const TraktSettingsScreen: React.FC = () => {
await traktService.logout();
setIsAuthenticated(false);
setUserProfile(null);
// Refresh auth status in the integration hook to ensure UI consistency
await refreshAuthStatus();
} catch (error) {
logger.error('[TraktSettingsScreen] Error signing out:', error);
openAlert('Error', 'Failed to sign out of Trakt.');
@ -494,6 +496,14 @@ const TraktSettingsScreen: React.FC = () => {
</View>
)}
</ScrollView>
<CustomAlert
visible={alertVisible}
title={alertTitle}
message={alertMessage}
onClose={() => setAlertVisible(false)}
actions={alertActions}
/>
</SafeAreaView>
);
};

View file

@ -14,7 +14,7 @@ interface CachedImage {
class ImageCacheService {
private cache = new Map<string, CachedImage>();
private readonly CACHE_DURATION = 24 * 60 * 60 * 1000; // 24 hours
private readonly CACHE_DURATION = Infinity; // Session-only: valid until app close
private readonly MAX_CACHE_SIZE = 25; // Further reduced maximum number of cached images
private readonly MAX_MEMORY_MB = 40; // Further reduced maximum memory usage in MB
private currentMemoryUsage = 0;