Android: Dealing with server cache

Updated 14 December 2016

Save

Caching is done on server side to enhance the speed of the server as active data is stored in caches, a relatively smaller and faster memory, and made available to customer whenever request hits. The validity of the data is based upon its expiration time. But sometimes this cache on server ends up giving you stale response for your android Application which in any case is wrong. So how can we control this behavior? We can do this using Http header for controlling cache i.e. Cache-Control.

 

Cache-Control

The Http header Cache-Control give us everything we need, we just have to use it efficiently based on the issues we are getting.

We can set many values to the Cache-Control header. There are many variants of this header such as

public: It lets server know that the response is not specific to any single user.

private: Opposite of public. It sets the response is specific to a single customer e.g. single browser.

max-age=[seconds]: It sets the maximum time upto which the response is treated as fresh. A 0 as seconds means that the response just expires right away.

no-cache: It tells server to do not cache the current request.

and many more.

You can set multiple of then in one go as

or

Just use according to you situation and you will definitely get results.

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home