添加,删除或更新数据后如何刷新缓存?

时间:2018-11-20 06:11:31

标签: android android-studio caching retrofit okhttp

因为当我插入,删除,更新数据时,数据列表尚未更新。修改数据后,请帮助刷新缓存,以便显示列表也将在修改后更新。

我的CacheInterceptor:

#include <stdio.h>

long double factorial(long double n,long double base = 1){
  if (n <= 1){
    return 1*base;
  }else{
    return factorial(n-1,n * base);
  }
}  
int main(){  
    printf("%.0Lf\n",factorial(25));     // this result is correct

    printf("%.0Lf\n",factorial(26));    
    //correct result is 403291461126605635584000000,but it return 403291461126605635592388608
    return 0;
}

显示数据:

public Response intercept(Chain chain) throws IOException
    {
        Response originalResponse = chain.proceed(chain.request());
        if ( Utils.isNetworkAvailable(context) )
        {
            int maxAge = 60; // read from cache for 1 minute
            return originalResponse.newBuilder()
                    .header("Cache-Control", "public, max-age=" + maxAge)
                    .build();
        }
        else
        {
            int maxStale = 60 * 60 * 24 * 28; // tolerate 4-weeks stale
            return originalResponse.newBuilder()
                    .header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale)
                    .build();
        }

插入数据:

                    for(Result result : commitment.getResultlist())
                    {
                        Log.e("id", String.valueOf(result.getId()) );
                        Log.e("Title", result.getTitle());
                        Log.e("Description", result.getDescription());

                        textResult.append(String.valueOf(result.getId()) + " ,");
                        textResult.append(result.getTitle());
                        textResult.append(", " + result.getDescription() + "\n\n");

0 个答案:

没有答案