Skip to content
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

How does downloadonly works ? #4229

Closed
yoobi opened this issue May 20, 2020 · 5 comments
Closed

How does downloadonly works ? #4229

yoobi opened this issue May 20, 2020 · 5 comments
Labels

Comments

@yoobi
Copy link

yoobi commented May 20, 2020

Glide Version:

//Glide
    kapt 'com.github.bumptech.glide:compiler:4.11.0'
    implementation 'com.github.bumptech.glide:glide:4.11.0'
    implementation 'com.github.bumptech.glide:annotations:4.11.0'
    implementation('com.github.bumptech.glide:okhttp3-integration:4.11.0'){
        exclude group: 'glide-parent'
    }

Integration libraries:

//OkHttp
    // Don't update okhttp3:okhttp:3.12.10, this version handle APK < 21
    //noinspection GradleDependency
    implementation("com.squareup.okhttp3:okhttp:3.12.10") { force = true }
    //noinspection GradleDependency
    implementation 'com.squareup.okhttp3:logging-interceptor:3.12.10'

Device/Android Version:
Galaxy S3 Neo, Nexus4 and Galaxy S7 Edge

Issue details / Repro steps / Use case background:
I'm trying out Glide and I'm still lacking some knowledge about this amazing library.
Here is the context, I've got an image sprite which is appended by number for each minute of the video. I'd like to preload 3 minutes of the video using Glide with the code below and then use that same image to make transformation.

Question 1 : if I use the for-loop below, will Glide download the 3 images everytime or will it check before downloading if it got the image in cache ? and when I'll use Glide with the same url later will it take it from cache or re-download the whole sprite ?

Question 2: Does using DiskCacheStrategy.DATA on the image to download it and then using DiskCacheStrategy.ALL on the override image will make Glide download the image or will it use the one in cache from before ?

Glide load line / GlideModule (if any) / list Adapter code (if any):

// Init with pre-load
for(i in 1..3) {
    GlideApp.with(this)
        .downloadOnly()
        .diskCacheStrategy(DiskCacheStrategy.DATA) // Cache resource before it's decoded
        .load("$MOSAIQUE_URL$i.jpg")
        .submit(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
}

// Using Glide to transform my image
GlideApp.with(scrubbingPreview)
    .load(thumbnailUrl) // which is "${MOSAIQUE_URL}1.jpg" or "${MOSAIQUE_URL}2.jpg"
    .diskCacheStrategy(DiskCacheStrategy.ALL)
    .override(Target.SIZE_ORIGINAL,Target.SIZE_ORIGINAL)   
    .transform(GlideThumbnailTransformation(position)
    .into(scrubbingPreview)
@yoobi
Copy link
Author

yoobi commented May 20, 2020

After looking into the doc and more precisely the caching part I found this for my first question, but I'm still not sure about what is the behaviour of Glide for the question 2

The first two steps check to see if the resource is in memory and if so, return the image immediately. The second two steps check to see if the image is on disk and return quickly, but asynchronously.

If all four steps fail to find the image, then Glide will go back to the original source to retrieve the data (the original File, Uri, Url etc).

If I understand correctly, even if I use downloadOnly and this image is in either memory or disk cache it won't download it again.


For example: If I load 20 images (from 1 to 20) and my memory cache can only contains 15, only the 15 most used will be in memory cache whereas the the disk cache will have the remaining 5 and will retrieve one of these if I load it into one of my component.

Is that how Glide manage memory ?

@stale
Copy link

stale bot commented May 30, 2020

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

@stale stale bot added the stale label May 30, 2020
@sjudd
Copy link
Collaborator

sjudd commented Jun 2, 2020

To answer question #2, ALL will use the DATA cache if the original image is present, but it will also cache the fully decoded/transformed image as well. Both the original and the transformed copy will end u in cache.

These caching strategies apply only to the on disk cache, not the in memory one.

The in memory cache only caches fully decoded/transformed results. The closest disk cache analogue is RESOURCE

@stale stale bot removed the stale label Jun 2, 2020
@yoobi
Copy link
Author

yoobi commented Jun 3, 2020

Okay, thank you for your answer, so there is no way to force an image to be in memory cache ?
Here is an example of RESOURCE and ALL, video example

The first time the thumb are displayed there is a blank when changing to another (I've used log and it was because the image was either in DATA_DISK_CACHE or RESOURCE_DISK_CACHE, but the second time there is no flicker because all the image are fetch from MEMORY_CACHE

@stale
Copy link

stale bot commented Jun 10, 2020

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

@stale stale bot added the stale label Jun 10, 2020
@stale stale bot closed this as completed Jun 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants