<p dir="auto">**Glide Version : 3.6.1 <em>_:<br>
<em>_Samsung Galaxy S4/Android 5.0.1</em></em>:<br>
<strong>Monitor call with Charles</strong>:</p>
<p dir="auto">Hello,<br>
For specific reasons, I have to change the cache folder, I did it with a glideModule extension :</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="public class GlideConfiguration implements GlideModule {
    @Override
    public void applyOptions(final Context context, GlideBuilder builder) {
        builder.setDiskCache(new DiskCache.Factory() {

            @Override
            public DiskCache build() {
                String dataDirPath = context.getApplicationInfo().dataDir;
                File cacheLocation = new File(dataDirPath + &quot;/media&quot;);
                if(!cacheLocation.exists()) {
                    boolean success = cacheLocation.mkdirs();
                    if(success) System.out.println(&quot;build succeed&quot;);
                }
                return DiskLruCacheWrapper.get(cacheLocation, 20000000);
            }
        });
    }

    @Override
    public void registerComponents(Context context, Glide glide) {

    }
}"><pre class="notranslate"><span class="pl-k">public</span> <span class="pl-k">class</span> <span class="pl-smi">GlideConfiguration</span> <span class="pl-k">implements</span> <span class="pl-smi">GlideModule</span> {
    <span class="pl-c1">@</span><span class="pl-c1">Override</span>
    <span class="pl-k">public</span> <span class="pl-smi">void</span> <span class="pl-en">applyOptions</span>(<span class="pl-k">final</span> <span class="pl-smi">Context</span> <span class="pl-s1">context</span>, <span class="pl-smi">GlideBuilder</span> <span class="pl-s1">builder</span>) {
        <span class="pl-s1">builder</span>.<span class="pl-en">setDiskCache</span>(<span class="pl-k">new</span> <span class="pl-smi">DiskCache</span>.<span class="pl-smi">Factory</span>() {

            <span class="pl-c1">@</span><span class="pl-c1">Override</span>
            <span class="pl-k">public</span> <span class="pl-smi">DiskCache</span> <span class="pl-en">build</span>() {
                <span class="pl-smi">String</span> <span class="pl-s1">dataDirPath</span> = <span class="pl-s1">context</span>.<span class="pl-en">getApplicationInfo</span>().<span class="pl-s1">dataDir</span>;
                <span class="pl-smi">File</span> <span class="pl-s1">cacheLocation</span> = <span class="pl-k">new</span> <span class="pl-smi">File</span>(<span class="pl-s1">dataDirPath</span> + <span class="pl-s">"/media"</span>);
                <span class="pl-k">if</span>(!<span class="pl-s1">cacheLocation</span>.<span class="pl-en">exists</span>()) {
                    <span class="pl-smi">boolean</span> <span class="pl-s1">success</span> = <span class="pl-s1">cacheLocation</span>.<span class="pl-en">mkdirs</span>();
                    <span class="pl-k">if</span>(<span class="pl-s1">success</span>) <span class="pl-smi">System</span>.<span class="pl-s1">out</span>.<span class="pl-en">println</span>(<span class="pl-s">"build succeed"</span>);
                }
                <span class="pl-k">return</span> <span class="pl-smi">DiskLruCacheWrapper</span>.<span class="pl-en">get</span>(<span class="pl-s1">cacheLocation</span>, <span class="pl-c1">20000000</span>);
            }
        });
    }

    <span class="pl-c1">@</span><span class="pl-c1">Override</span>
    <span class="pl-k">public</span> <span class="pl-smi">void</span> <span class="pl-en">registerComponents</span>(<span class="pl-smi">Context</span> <span class="pl-s1">context</span>, <span class="pl-smi">Glide</span> <span class="pl-s1">glide</span>) {

    }
}</pre></div>
<p dir="auto">And I also need to rename my cached files, I did it with dowloadOnly(..) :</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Glide.with(this)
            .load(&quot;http://www.wired.com/wp-content/uploads/2015/09/google-logo.jpg&quot;)
            .downloadOnly(new SimpleTarget&lt;File&gt;() {
                @Override
                public void onResourceReady(File resource, GlideAnimation&lt;? super File&gt; glideAnimation) {
                    File folder = resource.getParentFile();
                    if (folder.exists() &amp;&amp; folder.isDirectory()) {
                        File newPath = new File(folder, &quot;google-logo&quot;);
                        /*
                            NOTICE : renameTo change the filesystem path BUT NOT the File object
                            so resource.getPath() will return the OLD path
                            but resource.exists() return false while newPath.exists() return TRUE
                            so the file is changed as we want to.
                         */
                        resource.renameTo(newPath);
                    }
                }

            });"><pre class="notranslate"><span class="pl-smi">Glide</span>.<span class="pl-en">with</span>(<span class="pl-smi">this</span>)
            .<span class="pl-en">load</span>(<span class="pl-s">"http://www.wired.com/wp-content/uploads/2015/09/google-logo.jpg"</span>)
            .<span class="pl-en">downloadOnly</span>(<span class="pl-k">new</span> <span class="pl-smi">SimpleTarget</span>&lt;<span class="pl-smi">File</span>&gt;() {
                <span class="pl-c1">@</span><span class="pl-c1">Override</span>
                <span class="pl-k">public</span> <span class="pl-smi">void</span> <span class="pl-en">onResourceReady</span>(<span class="pl-smi">File</span> <span class="pl-s1">resource</span>, <span class="pl-smi">GlideAnimation</span>&lt;? <span class="pl-en">super</span> <span class="pl-smi">File</span>&gt; <span class="pl-s1">glideAnimation</span>) {
                    <span class="pl-smi">File</span> <span class="pl-s1">folder</span> = <span class="pl-s1">resource</span>.<span class="pl-en">getParentFile</span>();
                    <span class="pl-k">if</span> (<span class="pl-s1">folder</span>.<span class="pl-en">exists</span>() &amp;&amp; <span class="pl-s1">folder</span>.<span class="pl-en">isDirectory</span>()) {
                        <span class="pl-smi">File</span> <span class="pl-s1">newPath</span> = <span class="pl-k">new</span> <span class="pl-smi">File</span>(<span class="pl-s1">folder</span>, <span class="pl-s">"google-logo"</span>);
                        <span class="pl-c">/*</span>
<span class="pl-c">                            NOTICE : renameTo change the filesystem path BUT NOT the File object</span>
<span class="pl-c">                            so resource.getPath() will return the OLD path</span>
<span class="pl-c">                            but resource.exists() return false while newPath.exists() return TRUE</span>
<span class="pl-c">                            so the file is changed as we want to.</span>
<span class="pl-c">                         */</span>
                        <span class="pl-s1">resource</span>.<span class="pl-en">renameTo</span>(<span class="pl-s1">newPath</span>);
                    }
                }

            });</pre></div>
<p dir="auto">while I'm in-app it works fine and will not call the web to find the image for each simple call with load(..).into(imageView);<br>
But if I close or kill the app and relaunch it, the first call with code above is performed again.<br>
Is there a way to make my changes persistent? Is there a cleaner way to do what I want? I need to be able to change both the location and the name of cached files.<br>
Thanks !</p>
<p dir="auto">With Glide 4.0, the RequestOptions seems affected by ordering in API level 17.<br>
It makes rounded corners cannot exist with fitCenter at the same time.<br>
The following code will have a perfect scaled image but no rounded corner.<br>
(Work perfectly on other version.)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="RequestOptions options = new RequestOptions();
options.transform(roundedCorners);
options.fitCenter();"><pre class="notranslate"><code class="notranslate">RequestOptions options = new RequestOptions();
options.transform(roundedCorners);
options.fitCenter();
</code></pre></div>