3

I am using FFImageLoading instead of Image in my project for more advanced features like placeholders. In my project, there is a list of images needs to show. So I am using a listview for the same.

<ListView x:Name="membersList" ItemTapped="Handle_ItemTappedMember" HorizontalOptions="FillAndExpand" HasUnevenRows="true" SeparatorVisibility="None" BackgroundColor="#EEEEEE" Grid.Row="0" Grid.Column="0">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <ViewCell.View>
                            <StackLayout Orientation="Horizontal" Padding="5,5,5,5" HeightRequest="75" Margin="10,5,10,5" BackgroundColor="White" HorizontalOptions="FillAndExpand">
                                <ffimageloading:CachedImage Source="{Binding imageUrl}" x:Name="patImage" WidthRequest="60" HeightRequest="60" Aspect="AspectFill" VerticalOptions="Center">
                                    <ffimageloading:CachedImage.Transformations>
                                        <fftransformations:CircleTransformation />
                                    </ffimageloading:CachedImage.Transformations>
                                </ffimageloading:CachedImage>
                                <StackLayout Spacing="3" Orientation="Vertical" VerticalOptions="Center" HorizontalOptions="FillAndExpand">
                                    <Label FontAttributes="Bold" FontSize="14" TextColor="#212121" Text="{Binding FullName}" />
                                    <Label FontSize="12" TextColor="#212121" Text="{Binding Relation}" />
                                    <Label FontSize="12" TextColor="#212121" Text="{Binding Pat_ID}" />
                                </StackLayout>
                            </StackLayout>
                        </ViewCell.View>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

My problem is that I don't want to use Caching techniques here since my image from server may be changed without change the URL.

I know how to clear a single image view's cache with FFImageLoading

await CachedImage.InvalidateCache(Image.Source, CacheType.All, true);

But how to achieve this in ListView? I am using Binding property to load images here.

ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196
Alex Chengalan
  • 8,211
  • 4
  • 42
  • 56

2 Answers2

6

After some time spend on the same, I have cleared my problems. In the end it was very simple. In my listview's binding model class, when setting the imageUrl I just cleared cache at the same time with that url.

private string mImageUrl { get; set; }
public string imageUrl
{
get{
     return mImageUrl;
   };
set{
     mImageUrl = value;
     await CachedImage.InvalidateCache(mImageUrl, CacheType.All, true);
   };
}

This will clear the cached image with that imageUrl as key. Thank you everyone for your supports. Happy coding :)

Alex Chengalan
  • 8,211
  • 4
  • 42
  • 56
1

await not working without async so I added the async method for clean cache.

private string mImageUrl { get; set; }
public string imageUrl
{
get{
     return mImageUrl;
   };
set{
     mImageUrl = value;
     cleanCache();

   };
}

private async void cleanCache()
{
   await CachedImage.InvalidateCache(ImageURL, CacheType.All, true);
}
Adil Saiyad
  • 1,582
  • 2
  • 17
  • 34