Search code examples
javaandroidcachinguniversal-image-loader

How I can implement two caching strategy in UIL


How I can impement two cahing strategy in one application. Eg images from one app section should be cashing in one folder and have max memory/time limit etc. And images from another section should be have another folder etc. These strategies should not depend on each other.


Solution

  • ImageLoader is singleton but it provides protected constructor so you can extend ImageLoader and create the 2nd singleton:

    public class ImageLoader2 extends ImageLoader {
    
        private volatile static ImageLoader instance;
    
        /** Returns singleton class instance */
        public static ImageLoader getInstance() {
            if (instance == null) {
                synchronized (ImageLoader2.class) {
                    if (instance == null) {
                        instance = new ImageLoader2();
                    }
                }
            }
            return instance;
        }
    }
    

    and use it with other configuration.