Search code examples
androidfirebasefirebase-realtime-databaseokhttpcache-control

Why Firebase Database REST API returns no-cache header


I have an android application which is using OkHttp client and i request some data in my firebase realtime database using it's rest api Firebase. Firebase implements ETAG and OkHttp is properly doing conditional requests. But it also returns Cache-Control: no-cache header which means OkHttp will use cache only during conditional-get, but i need to control cache (set max-stale) or to use cache when there is no network.

Can i request Firebase so it gives different Cache-control value?


Solution

  • The Firebase Database returns that header to indicate intermediate layers should not cache the data, as it may be depend on authentication state.

    There is no way to tell the database to not return that flag.

    Keep in mind: while OkHttp may not cache the data, your application can store the results. This is the intended behavior, since your application can actually verify that the user is authorized to access the data, while OkHttp has no way to do so.