3

I use Glide library for Android. I want to set the cache in my custom folder, so the standard cache folder can be clean (with Master Clean for example). For this reason I use this code from manual, but this don't work for me.

My code:

DiskCache.Factory diskCacheFactory = new DiskCache.Factory() {
            @Override
            public DiskCache build() {
                DiskCache diskCache = DiskLruCacheWrapper.get(getFilesDir(), 1024*1024*100);
                return diskCache;
            }
        };
        new GlideBuilder(this).setDiskCache(diskCacheFactory);
        Glide.with(this)
                .load("http://www.website.com/1.jpg")
                .into(imageView);

After I run this app Glide saves the image in the default folder.

Sam Judd
  • 7,317
  • 1
  • 38
  • 38

2 Answers2

8

In Glide 3.5, Glide.isSetup() and Glide.setup() are deprecated. The best way to do this is to use GlideModules to do this kind of configuration lazily. Check out the wiki page on configuration.

Sam Judd
  • 7,317
  • 1
  • 38
  • 38
  • What if one wanted a different configuration in some Activity? For example, say you wanted a different cache location for certain images? – mkuech Mar 26 '15 at 18:22
  • 1
    @mkuech the configuration set in GlideBuilder is global. Individual requests typically allow you to set more specific options, some of which may override the global defaults. It's not currently possible to change the cache location on a per request basis, although it's something that has come up before. Feel free to open a new issue on GitHub: https://github.com/bumptech/glide/issues/new – Sam Judd Apr 14 '15 at 14:57
1

Try use:

if (!Glide.isSetup()) {
   GlideBuilder gb = new GlideBuilder(this);
   DiskCache dlw = DiskLruCacheWrapper.get(new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/myCatch/"), 250 * 1024 * 1024);
   gb.setDiskCache(dlw);
   Glide.setup(gb);
}
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
Artem
  • 4,569
  • 12
  • 44
  • 86