如何从Fresco Simple Drawee中清除缓存

3

我想使用Fresco库从simple drawee中删除缓存,因为如果从server更改了image,那么在simple drawee中仍会显示旧的图像。以下是我的代码。

    public class FrescoSimpleDraweeActivity extends Activity {

    private SimpleDraweeView simpleDraweeView1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Fresco.initialize(this);
        setContentView(R.layout.activity_fresco_simple_drawee);


        Log.e("Fresco simple activity ","is calling...");

        simpleDraweeView1 = (SimpleDraweeView) findViewById(R.id.simpleDraweeView1);

        Uri imageUri = Uri.parse("http://i.imgur.com/76Jfv9b.jpg");
//        simpleDraweeView1.setImageURI(imageUri);


        //If we used to load image from network then use it otherwiese not.
        // return immidiate result if thumb store using (.setProgressiveRenderingEnabled(true)) (only local URI)

        ImageRequest request = ImageRequestBuilder.newBuilderWithSource(imageUri)
                .setProgressiveRenderingEnabled(true)
                .setLocalThumbnailPreviewsEnabled(true)
                .build();

        ControllerListener listener = new BaseControllerListener();

        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setUri(imageUri)
                .setImageRequest(request)
                .setTapToRetryEnabled(true)
                .setOldController(simpleDraweeView1.getController())
                .setControllerListener(listener)
                .setTapToRetryEnabled(true)
                .build();

        simpleDraweeView1.setController(controller);



    }
}

以下是我的 XML 代码

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Activity.Fresco.FrescoSimpleDraweeActivity">

    <TextView
        android:id="@+id/tvTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="This is Fresco Drawee Example" />
    <!--fresco:failureImage="@drawable/failure"-->

    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/simpleDraweeView1"
        android:layout_width="200dp"
        android:layout_height="200dp"
        fresco:failureImage="@drawable/failure"
        fresco:progressBarImage="@drawable/progress"
        fresco:progressBarImageScaleType="centerInside"
        fresco:roundAsCircle="true"
        fresco:roundBottomLeft="true"
        fresco:roundBottomRight="true"
        fresco:roundTopLeft="true"
        fresco:roundTopRight="true"
        fresco:roundedCornerRadius="50dp"
        fresco:roundingBorderColor="@color/red"
        fresco:roundingBorderWidth="2dp"
        fresco:retryImage="@drawable/retry"
        fresco:retryImageScaleType="centerCrop"
        fresco:actualImageScaleType="centerCrop"
        android:layout_below="@+id/tvTitle"
         />


    <!--for round image border use below-->

    <!--fresco:roundedCornerRadius="50dp"-->
    <!--fresco:roundTopLeft="true"-->
    <!--fresco:roundTopRight="true"-->
    <!--fresco:roundBottomLeft="true"-->
    <!--fresco:roundBottomRight="true"-->


</RelativeLayout>

每当您需要清除缓存时,请尝试在图像URL后附加?timestamp=xxxxx。显然,将xxxx替换为当前时间。 - Richard Le Mesurier
1个回答

2

@Sakib Syed,您可以尝试使用这段代码,希望能对您有所帮助。

    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    imagePipeline.clearMemoryCaches();
    imagePipeline.clearDiskCaches();

//组合上述两行代码

    imagePipeline.clearCaches();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接