Copy screen caching to memory

I want to load and cache images only in memory, and not pass them to the view, and then when I need them to load into the user interface in order to get them from the memory cache, if they exist 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 I make a call to load this uri into ImageView, it will still load it from the path, not from memory.

Is there any other way to cache images in memory without loading them into the user interface?

+6
source share
2 answers

In fact, I found an API preload method for this purpose: pre-launch the API change log

+3
source

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

Here is a sample code on the page showing how the file will be loaded into the cache without displaying the image in the user interface:

 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 configure Glide so that caching is enabled: https://github.com/bumptech/glide/wiki/Configuration

+3
source

Source: https://habr.com/ru/post/984913/


All Articles