question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to disable image caching

See original GitHub issue

I want the images loaded from URL. the images may change every week. the slider won’t load and show new images on the URL. what should I do to disable caching? I also cleared app’s data but couldn’t get new Images. here’s my code from sample:

for (String name : imgList) {
TextSliderView textSliderView = new TextSliderView(mActivity);
            textSliderView
                    .description("")
                    .image(mActivity.getString(R.string.temp_url) + name)
                    .setScaleType(BaseSliderView.ScaleType.CenterCrop);
            textSliderView.bundle(new Bundle());
            textSliderView.getBundle()
                    .putString("extra", "");

            mDemoSlider.addSlider(textSliderView);
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8

github_iconTop GitHub Comments

3reactions
adnaanaeemcommented, May 28, 2017

Thankx for reply 😃 … But i have already done my project…

On May 21, 2017 11:42 AM, “erlangparasu” notifications@github.com wrote:

CustomBaseSliderView.java :

public abstract class CustomBaseSliderView extends BaseSliderView {

private String mUrl;
private File mFile;
private int mRes;
private ImageLoadListener mLoadListener;
private RequestCreator mRequestCreator;

protected CustomBaseSliderView(Context context) {
    super(context);
}

public RequestCreator getRequestCreator() {
    return mRequestCreator;
}

@Override
public BaseSliderView image(String url) {
    mUrl = url;
    return super.image(url);
}

@Override
public BaseSliderView image(File file) {
    mFile = file;
    return super.image(file);
}

@Override
public BaseSliderView image(int res) {
    mRes = res;
    return super.image(res);
}

@Override
protected void bindEventAndShow(final View v, ImageView targetImageView) {
    super.bindEventAndShow(v, targetImageView);
}

protected void bindEventAndShow(final View v, ImageView targetImageView, boolean disableCacheAndStore) {
    if (!disableCacheAndStore) {
        super.bindEventAndShow(v, targetImageView);
        return;
    }

    final BaseSliderView me = this;

    v.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mOnSliderClickListener != null) {
                mOnSliderClickListener.onSliderClick(me);
            }
        }
    });

    if (targetImageView == null)
        return;

    if (mLoadListener != null) {
        mLoadListener.onStart(me);
    }

    Picasso p = (getPicasso() != null) ? getPicasso() : Picasso.with(mContext);
    mRequestCreator = null;
    if (getUrl() != null) {
        mRequestCreator = p.load(getUrl());
    } else if (mFile != null) {
        mRequestCreator = p.load(mFile);
    } else if (mRes != 0) {
        mRequestCreator = p.load(mRes);
    } else {
        return;
    }

    if (mRequestCreator == null) {
        return;
    }

    //
    mRequestCreator.networkPolicy(NetworkPolicy.NO_CACHE, NetworkPolicy.NO_STORE);
    mRequestCreator.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE);
    //

    if (getEmpty() != 0) {
        mRequestCreator.placeholder(getEmpty());
    }

    if (getError() != 0) {
        mRequestCreator.error(getError());
    }

    switch (getScaleType()) {
        case Fit:
            mRequestCreator.fit();
            break;
        case CenterCrop:
            mRequestCreator.fit().centerCrop();
            break;
        case CenterInside:
            mRequestCreator.fit().centerInside();
            break;
    }

    mRequestCreator.into(targetImageView, new Callback() {
        @Override
        public void onSuccess() {
            if (v.findViewById(com.daimajia.slider.library.R.id.loading_bar) != null) {
                v.findViewById(com.daimajia.slider.library.R.id.loading_bar).setVisibility(View.INVISIBLE);
            }
        }

        @Override
        public void onError() {
            if (mLoadListener != null) {
                mLoadListener.onEnd(false, me);
            }
            if (v.findViewById(com.daimajia.slider.library.R.id.loading_bar) != null) {
                v.findViewById(com.daimajia.slider.library.R.id.loading_bar).setVisibility(View.INVISIBLE);
            }
        }
    });
}

}

CustomSliderView.java :

public class CustomSliderView extends CustomBaseSliderView {

public CustomSliderView(Context context) {
    super(context);
}

@Override
public View getView() {
    View v = LayoutInflater.from(getContext()).inflate(com.daimajia.slider.library.R.layout.render_type_default, null);
    ImageView target = (ImageView) v.findViewById(com.daimajia.slider.library.R.id.daimajia_slider_image);
    //bindEventAndShow(v, target);
    bindEventAndShow(v, target, true);
    return v;
}

}

usage :

    // ...

    int number = 0;
    for (String name : urlMaps.keySet()) {
        CustomSliderView customSliderView = new CustomSliderView(this);
        // initialize a SliderLayout
        customSliderView
                .description(String.valueOf(number))
                .image(urlMaps.get(name))
                .setScaleType(BaseSliderView.ScaleType.CenterInside)
                .setOnSliderClickListener(this);

        // extra information
        customSliderView.bundle(new Bundle());
        Bundle bundle = customSliderView.getBundle();
        bundle.putInt("image_number", number);
        mSliderLayout.addSlider(customSliderView );
    }

    // ...

is this working?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/daimajia/AndroidImageSlider/issues/291#issuecomment-302918655, or mute the thread https://github.com/notifications/unsubscribe-auth/AHdz1KOxglqEOpIWeY1KHJm9HopDHwjxks5r79zpgaJpZM4LxKe7 .

2reactions
Lithium-HDcommented, May 31, 2017

@erlangp thanks for your time, But I figured some other way to pass through this problem. I hope it helps others who have my problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable cache for some images - Stack Overflow
The absolute best way I've found to solve this is to use ETAGS inside a .htaccess file in your images directory. The following...
Read more >
How to prevent image from caching in javascript - Ajay Matharu
2 – Another solution is to write a javascript code so that the browser does not pick up image from the cache and...
Read more >
Prevent Caching Correctly? - MSDN - Microsoft
Adding a query string to the image URL would prevent the problematic effects of browser caching but it doesn't actually stop the image...
Read more >
How to disable your browser cache - Web Instinct
Click on the Network tab, then check the box to Disable cache. Disable Cache in Google Chrome Developer Tools. You can then close...
Read more >
Disable image cache? : r/firefox - Reddit
Hi, I have heard many a horror stories about image cacheing and would like to know how to disable. I do not want...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found