Android Question How to clear image cache in Amir_Glide?

Inman

Well-Known Member
Licensed User
Longtime User
I am trying to clear the entire cache of images loaded with Amir_Glide library by @alimanam3386. I tried to do the following in the Activity where the images are displayed.

B4X:
    Glide.Initializer.Default
    Glide.Glide.ClearDiskCache

and got this error

B4X:
java.lang.IllegalArgumentException: You must call this method on a background thread

How to do this correctly?
 

alimanam3386

Active Member
Licensed User
Longtime User
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User

From what I see it looks like this code is used to skip caching of a particular image so that it is always loaded live. In my case, I do want to cache all images. But when the user clicks a Refresh button, I want to clear the cache and load the images from the web again. How do I do that?
 
Upvote 0

alimanam3386

Active Member
Licensed User
Longtime User
? it is not for a particular image!!!

B4X:
Public Sub LoadImage(useCache As Boolean , holder As ImageView , link As Object)
    Dim g As Amir_Glide
    g.Initializer.Default
    g.RequestManager.ApplyDefaultRequestOptions(g.RO.SkipMemoryCache(useCache))
    g.Load(link).Into(holder)
End Sub
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
You are right, my mistake.

This is the code you posted in the other thread

B4X:
Activity.LoadLayout("1")
    ImageView1.Tag = Null
    Dim color2 As ColorDrawable
    color2.Initialize(Colors.Magenta,0)
    gl.Initializer.Default
    gl.RequestManager.ApplyDefaultRequestOptions(gl.RO.DiskCacheStrategy("NONE")) _
        .ApplyDefaultRequestOptions(gl.RO.SkipMemoryCache(True)) _
        .ApplyDefaultRequestOptions(gl.RO.ErrorDrawable(color2).Placeholder(color2).CenterCrop)
    gl.Load(photoAddress).Into(ImageView1)

Since gl.RequestManager is called immediately after gl.Initializer.Default, I am assuming this will set the configuration for Glide regarding caching. That means images loaded from now on using Glide will not be cached. But does the above code clear those images that have already been cached by Glide?
 
Upvote 0

alimanam3386

Active Member
Licensed User
Longtime User
Ok but this means the images that are already cached, still exists in phone's storage, right? How do I delete that image cache?

by calling :
B4X:
g.Glide.ClearDiskCache

This method should always be called on a background thread, since it is a blocking call. for more info please read the Glide documents.
 
Upvote 0
Top