Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set life time for image cache by using Android Universa Image Loader Library

In my android project, I am using Android-Universal-Image-Loader Lib (HERE) to load image from internet.

I want to save cache of those images for a period of time (example 1 day).

After the life time ends, it will load image again from internet (when my application starts). Otherwise, it will use cache.

Please help me

like image 946
MrSiro Avatar asked Dec 14 '25 06:12

MrSiro


1 Answers

Use LimitedAgeDiskCache for that.

File cacheDir = StorageUtils.getCacheDirectory(context);
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
        ...
        .diskCache(new LimitedAgeDiskCache(cacheDir, 24 * 60 * 60))
        .build();

ImageLoader.getInstance().init(config);
like image 112
nostra13 Avatar answered Dec 16 '25 21:12

nostra13



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!