prof18/RSS-Parser

Not an Issue Just Query : Can we cache the feed?

surabhi6 opened this issue · 7 comments

Hi,

I am using list of urlstring and each time loading takes so much time. Is there any way in which we can cache the parsed data...?

The library doesn't support caching at parsing level. You have to implement it in your business logic.

The library doesn't support caching at parsing level. You have to implement it in your business logic.

Why. Is it something that can be implemented. For me, the OkHttp client I am passing to the Parser supports caching. It's not caching the requests though.

I'm going to explore this. Thank for the suggestion

Please explore ASAP.

The RSS I am trying to Cache is: http://news.google.com/news?q=covid-19&hl=en-US&sort=date&gl=us&num=20&output=rss

My OkHttpClient:

fun getOkHttpClient(context: Context): OkHttpClient {
    val cacheSize = (5 * 1024 * 1024).toLong()
    val myCache = Cache(context.cacheDir, cacheSize)

    return OkHttpClient.Builder()
        .cache(myCache)
        .addInterceptor { chain ->
            var request = chain.request()
            request = if (isNetworkAvailable(context)!!)
                request.newBuilder().header("Cache-Control", "public, max-age=" + 5).build()
            else
                request.newBuilder().header(
                    "Cache-Control",
                    "public, only-if-cached, max-stale=" + 60 * 60 * 24 * 7
                ).build()
            chain.proceed(request)
        }
        .build()
}

Hi all, just to let you known that I'm working on it!

Commit: f985180

I think that a new release could be ready in a week or something.

Does the caching mechanism take into account the update interval set in the feed? It seems like the cache is a simple datetime-based cache where items just expire after certain time.

Hi,
the cache expiration is decided by the date passed in the Builder and does not take into account the expiration date of the feed. But that can be a nice addition, I will think about that. Thanks for raising the topic.