![]() Stale resources are caches that are past the cache duration. This directive prevents the use of stale resources. A resource can be cached by two actors, the end user or intermediary layers like CDNs which sit between the API server and the end user.Ĭache-Control: public means both end user and CDNs or intermediary proxies can cache the response.Ĭache-Control: private only allows the end user to cache the response. The public and private directives of Cache-Control are used to specify who can cache the response. You can also define the duration of shared caches by using the s-max-age directive. ![]() if both headers are present, Cache-Control takes precedence.įor example, ‘Cache-Control: max-age=1800’ means a resource can be retrieved from the cache for 1800 seconds or half an hour. It is a better alternative to the old Expires HTTP header. It includes a relative time value in seconds which means “X seconds after the response was generated by the origin server”. This directive controls how long a resource can be cached. Here are the most commonly used directives: It specifies how and for how long the browser should cache the response.įor this purpose, the Cache-Control header has multiple directives. The Cache-Control header is used to specify browser caching policies in both client requests and server responses, allowing for the browser to store local copies of resources for faster retrieval. So without further ado, let’s go through these headers. With appropriate use of these headers, response times can be improved and server load reduced. When to validate the cache to get updated data.By using HTTP headers, an origin server can specify the following: They let the API’s origin server communicate caching strategies to the client. ![]() HTTP cache headers provide a way to manage API caching in web applications effectively. Therefore it is essential for developers to understand how caching works with HTTP. This is API caching, and if done right, it results in better performance and latency while preventing excessive load on the API. If the cache contains the updated data, the request uses that data to satisfy the user's request. When a client requests some resources, the request first goes through a cache and then to the server. If more than one API requests result in the same response, we can store that response in a cache that is more readily available.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |