prof18 / RSS-Parser

A Kotlin Multiplatform library to parse a RSS Feed
Apache License 2.0
509 stars 129 forks source link

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

Closed surabhi6 closed 4 years ago

surabhi6 commented 4 years ago

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...?

prof18 commented 4 years ago

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

jeffnyauke commented 4 years ago

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.

prof18 commented 4 years ago

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

jeffnyauke commented 4 years ago

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()
}
prof18 commented 4 years ago

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.

mainrs commented 2 years ago

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.

prof18 commented 2 years ago

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.