Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glide caching off screen images in memory

I want to load and cache images only in memory and not pass them to a view and later on when I need them to be loaded on the UI to get them from memory cache if they existed in memory.

I tried:

Glide.with().load(uri).into(new SimpleTarget<GlideDrawable>(WIDTH,HEIGHT) 
{
     @Override
     public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
    //left empty
    }
  }
);

But when later on I make the call to load that uri in an ImageView it will still load it from the path and not memory.

Is there another way to have images cached in memory without loading them on the UI?

like image 718
feisal Avatar asked Apr 09 '15 18:04

feisal


2 Answers

Documentation on how to cache images on background thread can be found here.

Here is some example code from the page showing how a file would be downloaded to cache, without displaying the image in the UI:

FutureTarget<File> future = Glide.with(applicationContext)
.load(yourUrl)
.downloadOnly(500, 500);

// Can be omitted if you only want to have the data cached (same goes for the "future" instance variable
File cacheFile = future.get();

However, make sure you have configured Glide such that caching is enabled: https://github.com/bumptech/glide/wiki/Configuration

like image 92
Matt d' Avatar answered Sep 19 '22 11:09

Matt d'


Actually I found the preload method in API for this exact purpose: preload API change log

like image 30
feisal Avatar answered Sep 20 '22 11:09

feisal