<p dir="auto">In my app, I have a Recycler view with GridLayoutManager. The code I am using to load images bindImage method of recycler view adapter:</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@Override
public void onBindViewHolder(ImageViewHolder holder, int position) {
    GSImage dbImage = mLandscapeImagesList.get(position);
    File imageFile = new File(mImageDirectoryFile, dbImage.getImageName());

    Glide.with(MyImageFragement.this).load(imageFile).centerCrop().into(holder.imageView);

    int indexInSelectedImagesSet = mSelectedLandscapeImages.indexOf(dbImage);
    if (indexInSelectedImagesSet&gt;-1){
        holder.itemView.setSelected(true);
    } else {
        holder.itemView.setSelected(false);
    }

}"><pre class="notranslate"><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-s1">onBindViewHolder</span>(<span class="pl-smi">ImageViewHolder</span> <span class="pl-s1">holder</span>, <span class="pl-smi">int</span> <span class="pl-s1">position</span>) {
    <span class="pl-smi">GSImage</span> <span class="pl-s1">dbImage</span> = <span class="pl-s1">mLandscapeImagesList</span>.<span class="pl-en">get</span>(<span class="pl-s1">position</span>);
    <span class="pl-smi">File</span> <span class="pl-s1">imageFile</span> = <span class="pl-k">new</span> <span class="pl-smi">File</span>(<span class="pl-s1">mImageDirectoryFile</span>, <span class="pl-s1">dbImage</span>.<span class="pl-en">getImageName</span>());

    <span class="pl-smi">Glide</span>.<span class="pl-en">with</span>(<span class="pl-smi">MyImageFragement</span>.<span class="pl-smi">this</span>).<span class="pl-en">load</span>(<span class="pl-s1">imageFile</span>).<span class="pl-en">centerCrop</span>().<span class="pl-en">into</span>(<span class="pl-s1">holder</span>.<span class="pl-s1">imageView</span>);

    <span class="pl-smi">int</span> <span class="pl-s1">indexInSelectedImagesSet</span> = <span class="pl-s1">mSelectedLandscapeImages</span>.<span class="pl-en">indexOf</span>(<span class="pl-s1">dbImage</span>);
    <span class="pl-k">if</span> (<span class="pl-s1">indexInSelectedImagesSet</span>&gt;-<span class="pl-c1">1</span>){
        <span class="pl-s1">holder</span>.<span class="pl-s1">itemView</span>.<span class="pl-en">setSelected</span>(<span class="pl-c1">true</span>);
    } <span class="pl-k">else</span> {
        <span class="pl-s1">holder</span>.<span class="pl-s1">itemView</span>.<span class="pl-en">setSelected</span>(<span class="pl-c1">false</span>);
    }

}</pre></div>
<p dir="auto">The Cell layout I am using is:</p>
<div class="highlight highlight-text-xml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
     xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:background=&quot;@drawable/images_background&quot;
      android:layout_marginTop=&quot;9dp&quot;
      android:layout_marginLeft=&quot;10dp&quot;
      android:layout_marginRight=&quot;0dp&quot;
      android:layout_marginBottom=&quot;0dp&quot;
      android:padding=&quot;2dp&quot;&gt;

      &lt;com.gaurav.myProject.commons.AspectRatioImageView
                 android:id=&quot;@+id/image_thumb&quot;
                 android:layout_width=&quot;match_parent&quot;
                 android:layout_height=&quot;wrap_content&quot;
                 android:scaleType=&quot;fitXY&quot;
                 app:viewAspectRatio=&quot;1.33&quot;/&gt;

&lt;/RelativeLayout&gt;"><pre class="notranslate">&lt;?<span class="pl-ent">xml</span><span class="pl-e"> version</span>=<span class="pl-s"><span class="pl-pds">"</span>1.0<span class="pl-pds">"</span></span><span class="pl-e"> encoding</span>=<span class="pl-s"><span class="pl-pds">"</span>utf-8<span class="pl-pds">"</span></span>?&gt;
&lt;<span class="pl-ent">RelativeLayout</span> <span class="pl-e">xmlns</span><span class="pl-e">:</span><span class="pl-e">android</span>=<span class="pl-s"><span class="pl-pds">"</span>http://schemas.android.com/apk/res/android<span class="pl-pds">"</span></span>
     <span class="pl-e">xmlns</span><span class="pl-e">:</span><span class="pl-e">app</span>=<span class="pl-s"><span class="pl-pds">"</span>http://schemas.android.com/apk/res-auto<span class="pl-pds">"</span></span>
      <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_width</span>=<span class="pl-s"><span class="pl-pds">"</span>wrap_content<span class="pl-pds">"</span></span>
      <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_height</span>=<span class="pl-s"><span class="pl-pds">"</span>wrap_content<span class="pl-pds">"</span></span>
      <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">background</span>=<span class="pl-s"><span class="pl-pds">"</span>@drawable/images_background<span class="pl-pds">"</span></span>
      <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_marginTop</span>=<span class="pl-s"><span class="pl-pds">"</span>9dp<span class="pl-pds">"</span></span>
      <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_marginLeft</span>=<span class="pl-s"><span class="pl-pds">"</span>10dp<span class="pl-pds">"</span></span>
      <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_marginRight</span>=<span class="pl-s"><span class="pl-pds">"</span>0dp<span class="pl-pds">"</span></span>
      <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_marginBottom</span>=<span class="pl-s"><span class="pl-pds">"</span>0dp<span class="pl-pds">"</span></span>
      <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">padding</span>=<span class="pl-s"><span class="pl-pds">"</span>2dp<span class="pl-pds">"</span></span>&gt;

      &lt;<span class="pl-ent">com</span>.gaurav.myProject.commons.AspectRatioImageView
                 <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>@+id/image_thumb<span class="pl-pds">"</span></span>
                 <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_width</span>=<span class="pl-s"><span class="pl-pds">"</span>match_parent<span class="pl-pds">"</span></span>
                 <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_height</span>=<span class="pl-s"><span class="pl-pds">"</span>wrap_content<span class="pl-pds">"</span></span>
                 <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">scaleType</span>=<span class="pl-s"><span class="pl-pds">"</span>fitXY<span class="pl-pds">"</span></span>
                 <span class="pl-e">app</span><span class="pl-e">:</span><span class="pl-e">viewAspectRatio</span>=<span class="pl-s"><span class="pl-pds">"</span>1.33<span class="pl-pds">"</span></span>/&gt;

&lt;/<span class="pl-ent">RelativeLayout</span>&gt;</pre></div>
<p dir="auto">Here AspectRatioImageView(subclass of ImageView) automatically resizes the height of image view according to the provided aspect ratio.</p>
<p dir="auto">The above code is working fine on my devices (Xiaomi MiPad, ViewSonic Tablet, Android emaulators and Samsung Galaxy S3) but is not working correctly on my client's device (Samsung 10.1 inch tablet).<br>
In his end, images are being duplicated in the recycler grid. Also the the duplicates mostly occurs in adjacent recycler grid positions. I can't share any code as I even unable to reproduce the issue on my devices.</p>
<p dir="auto">Do you guys have any idea what could the cause of this? Can you please suggest me any thing that I can try?</p>
<p dir="auto">Thanks</p>
<p dir="auto">I'm trying to cache downloaded image from web using SimpleTarget like so:</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Glide.with(getContext())
                            .load(iurl)
                            .asBitmap()
                            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                            .skipMemoryCache(true)
                            .into(target);"><pre class="notranslate"><span class="pl-smi">Glide</span>.<span class="pl-en">with</span>(<span class="pl-en">getContext</span>())
                            .<span class="pl-en">load</span>(<span class="pl-s1">iurl</span>)
                            .<span class="pl-en">asBitmap</span>()
                            .<span class="pl-en">diskCacheStrategy</span>(<span class="pl-smi">DiskCacheStrategy</span>.<span class="pl-c1">SOURCE</span>)
                            .<span class="pl-en">skipMemoryCache</span>(<span class="pl-c1">true</span>)
                            .<span class="pl-en">into</span>(<span class="pl-s1">target</span>);</pre></div>
<p dir="auto">where target is initialized by :</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="SimpleTarget&lt;Bitmap&gt; target = new SimpleTarget&lt;Bitmap&gt;() {

        @Override
        public void onResourceReady(Bitmap resource,
                GlideAnimation&lt;? super Bitmap&gt;
                glideAnimation) {
            Log.d(LOG_TAG, &quot;image cached&quot;);
        }

        @Override
        public void onLoadFailed(Exception e, Drawable errorDrawable) {
            e.printStackTrace();

        }
    };"><pre class="notranslate"><span class="pl-smi">SimpleTarget</span>&lt;<span class="pl-smi">Bitmap</span>&gt; <span class="pl-s1">target</span> = <span class="pl-k">new</span> <span class="pl-smi">SimpleTarget</span>&lt;<span class="pl-smi">Bitmap</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">Bitmap</span> <span class="pl-s1">resource</span>,
                <span class="pl-smi">GlideAnimation</span>&lt;? <span class="pl-en">super</span> <span class="pl-smi">Bitmap</span>&gt;
                <span class="pl-s1">glideAnimation</span>) {
            <span class="pl-smi">Log</span>.<span class="pl-en">d</span>(<span class="pl-c1">LOG_TAG</span>, <span class="pl-s">"image cached"</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">onLoadFailed</span>(<span class="pl-smi">Exception</span> <span class="pl-s1">e</span>, <span class="pl-smi">Drawable</span> <span class="pl-s1">errorDrawable</span>) {
            <span class="pl-s1">e</span>.<span class="pl-en">printStackTrace</span>();

        }
    };</pre></div>
<p dir="auto">and in the fragment :</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Glide.with(imageView.getContext())
                .load(image_url)
                .asBitmap()
                .dontAnimate()
                .centerCrop()
                .override(MyApplication.getInstance().width,MyApplication.getInstance().height)
                .priority(Priority.IMMEDIATE)
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .into(imageView);"><pre class="notranslate"><span class="pl-smi">Glide</span>.<span class="pl-en">with</span>(<span class="pl-s1">imageView</span>.<span class="pl-en">getContext</span>())
                .<span class="pl-en">load</span>(<span class="pl-s1">image_url</span>)
                .<span class="pl-en">asBitmap</span>()
                .<span class="pl-en">dontAnimate</span>()
                .<span class="pl-en">centerCrop</span>()
                .<span class="pl-en">override</span>(<span class="pl-smi">MyApplication</span>.<span class="pl-en">getInstance</span>().<span class="pl-s1">width</span>,<span class="pl-smi">MyApplication</span>.<span class="pl-en">getInstance</span>().<span class="pl-s1">height</span>)
                .<span class="pl-en">priority</span>(<span class="pl-smi">Priority</span>.<span class="pl-c1">IMMEDIATE</span>)
                .<span class="pl-en">diskCacheStrategy</span>(<span class="pl-smi">DiskCacheStrategy</span>.<span class="pl-c1">SOURCE</span>)
                .<span class="pl-en">into</span>(<span class="pl-s1">imageView</span>);</pre></div>
<p dir="auto">where width and height is calculated according to the current configuration of the device:</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="DisplayMetrics displayMetrics = this.getResources().getDisplayMetrics();
        float dpWidth = displayMetrics.widthPixels / displayMetrics.density;
        if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
            if (dpWidth &lt; 600) {
                application_instance.width = 200;
                application_instance.height = 200;
            } else if (dpWidth &gt;= 600 &amp;&amp; dpWidth &lt; 720) {
                application_instance.width = 400;
                application_instance.height = 400;
            } else {
                application_instance.width = 800;
                application_instance.height = 800;
            }

        } else {
            if (dpWidth &lt; 600) {
                application_instance.width = 300;
                application_instance.height = 300;
            } else if (dpWidth &gt;= 600 &amp;&amp; dpWidth &lt; 720) {
                application_instance.width = 600;
                application_instance.height = 600;
            } else {
                application_instance.width = 640;
                application_instance.height = 640;
            }

        }"><pre class="notranslate"><span class="pl-smi">DisplayMetrics</span> <span class="pl-s1">displayMetrics</span> = <span class="pl-smi">this</span>.<span class="pl-en">getResources</span>().<span class="pl-en">getDisplayMetrics</span>();
        <span class="pl-smi">float</span> <span class="pl-s1">dpWidth</span> = <span class="pl-s1">displayMetrics</span>.<span class="pl-s1">widthPixels</span> / <span class="pl-s1">displayMetrics</span>.<span class="pl-s1">density</span>;
        <span class="pl-k">if</span> (<span class="pl-smi">this</span>.<span class="pl-en">getResources</span>().<span class="pl-en">getConfiguration</span>().<span class="pl-s1">orientation</span> == <span class="pl-smi">Configuration</span>.<span class="pl-c1">ORIENTATION_PORTRAIT</span>) {
            <span class="pl-k">if</span> (<span class="pl-s1">dpWidth</span> &lt; <span class="pl-c1">600</span>) {
                <span class="pl-s1">application_instance</span>.<span class="pl-s1">width</span> = <span class="pl-c1">200</span>;
                <span class="pl-s1">application_instance</span>.<span class="pl-s1">height</span> = <span class="pl-c1">200</span>;
            } <span class="pl-k">else</span> <span class="pl-k">if</span> (<span class="pl-s1">dpWidth</span> &gt;= <span class="pl-c1">600</span> &amp;&amp; <span class="pl-s1">dpWidth</span> &lt; <span class="pl-c1">720</span>) {
                <span class="pl-s1">application_instance</span>.<span class="pl-s1">width</span> = <span class="pl-c1">400</span>;
                <span class="pl-s1">application_instance</span>.<span class="pl-s1">height</span> = <span class="pl-c1">400</span>;
            } <span class="pl-k">else</span> {
                <span class="pl-s1">application_instance</span>.<span class="pl-s1">width</span> = <span class="pl-c1">800</span>;
                <span class="pl-s1">application_instance</span>.<span class="pl-s1">height</span> = <span class="pl-c1">800</span>;
            }

        } <span class="pl-k">else</span> {
            <span class="pl-k">if</span> (<span class="pl-s1">dpWidth</span> &lt; <span class="pl-c1">600</span>) {
                <span class="pl-s1">application_instance</span>.<span class="pl-s1">width</span> = <span class="pl-c1">300</span>;
                <span class="pl-s1">application_instance</span>.<span class="pl-s1">height</span> = <span class="pl-c1">300</span>;
            } <span class="pl-k">else</span> <span class="pl-k">if</span> (<span class="pl-s1">dpWidth</span> &gt;= <span class="pl-c1">600</span> &amp;&amp; <span class="pl-s1">dpWidth</span> &lt; <span class="pl-c1">720</span>) {
                <span class="pl-s1">application_instance</span>.<span class="pl-s1">width</span> = <span class="pl-c1">600</span>;
                <span class="pl-s1">application_instance</span>.<span class="pl-s1">height</span> = <span class="pl-c1">600</span>;
            } <span class="pl-k">else</span> {
                <span class="pl-s1">application_instance</span>.<span class="pl-s1">width</span> = <span class="pl-c1">640</span>;
                <span class="pl-s1">application_instance</span>.<span class="pl-s1">height</span> = <span class="pl-c1">640</span>;
            }

        }</pre></div>
<p dir="auto">and the image view in xml layout file :</p>
<div class="highlight highlight-text-xml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;ImageView
        android:id=&quot;@+id/grid_item_image_view&quot;
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;match_parent&quot;
        andr(oid:adjustViewBounds=&quot;true&quot; /&gt;"><pre class="notranslate">&lt;<span class="pl-ent">ImageView</span>
        <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>@+id/grid_item_image_view<span class="pl-pds">"</span></span>
        <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_width</span>=<span class="pl-s"><span class="pl-pds">"</span>match_parent<span class="pl-pds">"</span></span>
        <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_height</span>=<span class="pl-s"><span class="pl-pds">"</span>match_parent<span class="pl-pds">"</span></span>
        andr(oid:adjustViewBounds=<span class="pl-s"><span class="pl-pds">"</span>true<span class="pl-pds">"</span></span> /&gt;</pre></div>
<p dir="auto">each time the image is loaded, it's downloaded from web again and cached again and the result is a huge cache size ! ..What I need is How to prevent downloading the same image again if it exists in the Diskcache and remove it from cache when its url is removed from database ? I'm using Glide 3.7.0. Am I missing something or misunderstand it?. Please help. Thanks in advance.</p>