Friday, 29 July 2016

Glide: Caching basics

With a small reference from one of my previous blogs, Today's blog is regarding the Caching basics in Glide- Image Library.
Glide is a fast and efficient open source image loading framework for Android that wraps memory and disk caching, and resource pooling into a simple and easy to use interface.
Glide supports fetching, decoding, and displaying video stills, images, and animated GIFs.
Glide's primary focus is on making scrolling any kind of a list of images as smooth and fast as possible, but Glide is also effective for almost any case where you need to fetch, resize, and display a remote image.
With these features of glide, it also allows you to cache your images so that they can be showcased a bit faster when used frequently. But some times there is a need that you do not want to cache the images or your image URL due to some or the other reason, such as
-- Suppose the url which you are getting from your server is same but the image on that url is changed every time. In this case if the url is same then glide first check this url in its cache and if it founds that url in its cache it load the same image without requesting it again. this problem can be solved if -
I.   It is possible to always load the image from URL and not from cache. OR
II. It is possible to clear the image from cache before loading the new image from URL.

So the solution for this problem by using diskCacheStrategy() to handle the disk cache and you can skip the memory cache using skipMemoryCache() method as follows:

Glide.with(YourActivity.this)
    .load(imageURL)
    .diskCacheStrategy(DiskCacheStrategy.NONE)
    .skipMemoryCache(true)
    .into(yourImageView);

That's all.
Happy coding and remember "Code to make it better".

1 comment:

  1. Nekopoi Mod APK is a popular app for anime lovers to stream and enjoy their favorite series on Android devices. It offers a vast collection of anime titles with smooth playback and easy navigation. The how to nekopoi mod offline viewing guide helps users download episodes and watch them without an internet connection.

    ReplyDelete