-
-
Notifications
You must be signed in to change notification settings - Fork 9
Fix file:// URL handling, cache eviction, cache detection, and force reload with efficient disk cache tracking in Android image loader #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…rl for local files Co-authored-by: farfromrefug <[email protected]>
Co-authored-by: farfromrefug <[email protected]>
…eation Co-authored-by: farfromrefug <[email protected]>
Co-authored-by: farfromrefug <[email protected]>
|
@copilot evictAllForId should remove image and all "transforms" from disk and memory |
Co-authored-by: farfromrefug <[email protected]>
Fixed in 359fe41. The method now properly evicts from both disk (source + transformed) and memory cache. After disk eviction completes, it calls removeByModelAndSignature on the memory cache, then combines the results before invoking the callback. |
|
@copilot i have made some improvements around local image caching and eviction. But there is still an issue i cant figure out. Try to figure it out |
…instead of Glide cache Co-authored-by: farfromrefug <[email protected]>
Fixed in 4b5d0d0. The issue was that Glide doesn't copy local files to its disk cache (they're already on disk), so checking with |
|
@copilot this is not true. On the first run i can seem image loaded from "LOCAL" but if i run the app again it is then loaded form So i need a way to evict it from cache. So first rever your last changes about File.exists |
…ct decoded resource class Co-authored-by: farfromrefug <[email protected]>
Fixed in cff41c8. Reverted the File.exists() approach. Now correctly checks Glide's RESOURCE_DISK_CACHE using RecreatedResourceKey for local files. Key changes:
Local files are now properly detected in cache after first load. |
…ue' into copilot/fix-custom-glide-url-issue
|
@copilot so i added a new ModelSignatureDiskLruCacheWrapper class to use a custom DiskCache for better handling of eviction. |
…uCacheWrapper Co-authored-by: farfromrefug <[email protected]>
Implemented in 5d7da0a. Key improvements: ModelSignatureDiskLruCacheWrapper:
EvictionManager Integration:
All operations are thread-safe with comprehensive logging. |
|
@copilot ok i made some changes and almost everything works. Now i have one last issue:
How should i fix that? My prefer way would be to tell glide to NOT put that image into memory cache |
…nged content Co-authored-by: farfromrefug <[email protected]>
Fixed in aac83d0. Added
Usage when image file content changes: await imageView.forceReloadImage();This prevents Glide from caching the old drawable in memory during eviction and ensures fresh content is loaded. |
Loading local images with
file://URIs crashed withIllegalArgumentException: Expected URL scheme 'http' or 'https' but was 'file'. The code unconditionally wrapped all URIs inCustomGlideUrl, which uses OkHttp that only supports HTTP/HTTPS schemes.Additionally, fixed
evictAllForIdto properly evict from both disk and memory cache as intended, fixedisInDiskCacheAsyncto correctly detect local file presence in Glide's cache, implemented efficient key tracking inModelSignatureDiskLruCacheWrapperfor smart cache management, and addedforceReloadImage()method to handle stale cache issues when image content changes.Changes
isNetworkUri()helper to detect HTTP/HTTPS vs local URIsCustomGlideUrlonly for network requests needing headers/callbacks, plain strings for local filesloadImageWithGlide()andprefetchToCache()evictAllForId()to properly evict from both disk (source + transformed) and memory cache with smart strategy selectionisInDiskCacheAsync()to correctly detect local file:// URIs by checking Glide's RESOURCE_DISK_CACHE using ResourceCacheKeySaveKeysRequestListenerto enable proper cache key generationModelSignatureDiskLruCacheWrapperwith O(1) lookup, bulk eviction, and signature version managementforceReloadImage()method to bypass memory cache and reload changed image contentCache Eviction Fix
The
evictAllForIdmethod now correctly:ModelSignatureDiskLruCacheWrapper) is availableThis ensures images and all transforms are fully removed from both disk and memory as the method name implies.
Local File Cache Detection Fix
The
isInDiskCacheAsyncandisInDiskCacheBlockingmethods now correctly handle local file:// URIs:Problem: Local files are cached by Glide as decoded resources in RESOURCE_DISK_CACHE, not as source data. The code was incorrectly checking with
CustomDataCacheKeyfor source data (which doesn't exist for local files) and missing thedecodedResourceClassneeded to check ResourceCacheKey.Solution:
SaveKeysRequestListenernow automatically detects the resource class from the actual decoded resource (e.g.,BitmapDrawable) if not providedObjectKeysourceKey), skipCustomDataCacheKeycheck since Glide doesn't cache local file bytesRecreatedResourceKeyto check for the decoded/cached bitmap in RESOURCE_DISK_CACHEsourcePresentsince that IS the cached versionThis ensures that:
isInDiskCacheAsyncreturns true immediately after first load for local filesEnhanced Disk Cache with Efficient Key Tracking
Implemented comprehensive key tracking system in
ModelSignatureDiskLruCacheWrapper, similar toModelSignatureMemoryCache:Key Features:
New Methods in ModelSignatureDiskLruCacheWrapper:
containsByModelAndSignature(model, signature)- Check if entries exist without cache iterationremoveByModelAndSignature(model, signature)- Remove all matching entries (raw + transformed)removeAllExceptSignature(currentSignature)- Signature version migration supportgetStats()- Returns cache statistics [indexSize, diskCacheSize]New Methods in EvictionManager:
evictDiskByModelAndSignature()- Use efficient disk cache eviction when availableevictDiskExceptSignature()- Remove entries with different signature versionscontainsInDiskCacheByModelAndSignature()- Efficient existence checkgetDiskCacheStats()- Get cache statisticsPerformance Benefits:
Force Reload with Cache Bypass
Added
forceReloadImage()method to handle scenarios where image file content changes but the URI remains the same:Problem: When reloading an image after modifying its content locally:
Solution:
skipMemoryCacheOnNextLoadflag that bypasses memory cache for a single loadforceReloadImage()method that:Usage:
Key Features:
Cache Key Compatibility
SaveKeysRequestListenerhandles both model types correctly:CustomGlideUrl→ uses GlideUrl cache key for source, ResourceCacheKey for decoded resourcesObjectKey(uri)as sourceKey, ResourceCacheKey for decoded resourcesBoth work with
EvictionManageroperations and the enhanced disk cache tracking system. Same URI always uses same model type.Supported URI Types
file://→ string → Glide default file loader (fixed loading, cache detection, efficient eviction, and force reload)android.resource://→ string → Glide default resource loaderhttp://,https://→ CustomGlideUrl (when headers/callbacks) or stringOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.