question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Xamarin.Forms Android InvalidateCacheEntryAsync doesn't completely remove.

See original GitHub issue

Xamarin.Forms Android InvalidateCacheEntryAsync can’t completely remove individual cache with CacheKeyFactory.

Description

On Android with Xamarin.Forms, when using StreamImageSource for CachedImage.Source and setting CacheKeyFactory, InvalidateCacheEntryAsync method can’t completely remove individual cache.

On iOS, it can be removed and display the new image.

I use SQLite DB to manage images for my app and the record id is used as the cache key. And then I use the same key after removing the cache when an image is updated. But the previous image will soon revive and display it.

Steps to Reproduce

  1. Put a CachedImage specified CacheKeyFactory.
  2. Specify a StreamImageSource as the source.
  3. Execute InvalidateCacheEntryAsync(the key, All, true)
  4. Update the ImageSource.Source to the other source with the same key as previous.
  5. The new image will be reflected on CachedImage.
  6. Update it again.
  7. The previous image will be displayed.

Expected Behavior

Once InvalidateCacheEntryAsync method executes, the cache will be removed and the new image will be reflected when CahcedImage.Source is updated.

Actual Behavior

Each time InvalidateCacheEntryAsync method executes and the source is updated, either the previous image will revive or the new image will be reflected.

Basic Information

  • Version with issue: 2.4.4.859
  • Last known good version: none
  • Platform: Xamarin.Forms 3.4.0.1008975 / Android

Screenshots

  1. Initial state.

  2. Tap Update.

  3. Tap Update again.

Reproduction Link / Code

The Reproduction Project

Work Around

It removes the entry also from the cache of the reuse_pool.

public class ImageServiceEx:IImageServiceEx
{
    static ByteBoundStrongLruCache<SelfDisposingBitmapDrawable> _reusePool;
    static ByteBoundStrongLruCache<SelfDisposingBitmapDrawable> ReusePool
    {
        get
        {
            if (_reusePool != null)
                return _reusePool;

            var imageCache = ImageCache.Instance as ImageCache<SelfDisposingBitmapDrawable>;
            var fieldInfo = imageCache.GetType().GetField("_cache", BindingFlags.Instance | BindingFlags.NonPublic);
            var innerCache = (ReuseBitmapDrawableCache<SelfDisposingBitmapDrawable>)fieldInfo.GetValue(imageCache);
            fieldInfo = innerCache.GetType().GetField("reuse_pool", BindingFlags.Instance | BindingFlags.NonPublic);
            _reusePool = (ByteBoundStrongLruCache<SelfDisposingBitmapDrawable>)fieldInfo.GetValue(innerCache);

            return _reusePool;
        }
    }

    public async Task ForceInvalidateCacheEntryAsync(string key, CacheType cacheType, bool removeSimilar = false)
    {
        await ImageService.Instance.InvalidateCacheEntryAsync(key, cacheType, removeSimilar);
        ReusePool.Remove(key);
    }
}

Related link

#965

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
daniel-luberdacommented, Apr 18, 2019

Fixed. Thanks @GZidar 👍

1reaction
GZidarcommented, Mar 12, 2019

I have created a PR with the change we made to the package that resolved this issue for us.

https://github.com/luberda-molinet/FFImageLoading/pull/1213

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Xamarin.Forms] Removing cache entries doesn't work #965
Forms on Android with verbose logging. Removing a cache entry doesn't do anything, it immediately reloads the image from cache. Might be useful: ......
Read more >
Xamarin.Forms Android preserves old data even with ...
Is there some way to fix this or clear this cache? Even if I remove app from device, Studio on next build inserts...
Read more >
Xamarin.Forms 5.0.0.2612 (5.0.0 Service Release 15) ...
Release notes detailing new features, improvements, and issues fixed in Xamarin.Forms 5.0.0.2612 (5.0.0 Service Release 15)
Read more >
Xamarin.Forms 4.2.0.815419 (4.2.0 Service Release 2) ...
Release notes detailing new features, improvements, and issues fixed in Xamarin.Forms 4.2.0.815419 (4.2.0 Service Release 2)
Read more >
Xamarin.Forms, Akavache and I: storing, retrieving and ...
Forms together, I will show you some typical methods for storing, retrieving and deleting data from the cache instance we implemented in the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found