RESTful Web Services - Caching

RESTful Web Services - Caching

Caching refers to storing the server's response in the client itself, so the client doesn't have to request the same resource from the server again and again. The server's response should contain information about how caching should be done so that the client caches the response for a certain period of time or never caches the server's response.

The following are the headers that a server response can have to configure client caching.

Sr.No. Title and Description

one

date of

The date and time of the resource when it was created.

2

Last modified

The date and time the resource was last modified.

3

Cache-Control

The main header to control caching.

4

Expires

Expiration date and cache time.

five

Age

Duration in seconds since the resource was received from the server.

one

date of

The date and time of the resource when it was created.

Last modified

The date and time the resource was last modified.

3

Cache-Control

The main header to control caching.

4

Expires

Expiration date and cache time.

five

Age

Duration in seconds since the resource was received from the server.

Cache-Control header

Below are the details of the Cache-Control header.

one

public

Specifies that the resource is cached by any component.

2

Private

Specifies that the resource is only cached by the client and server, no intermediary can cache the resource.

3

no no cache / no-store

Specifies that the resource is not cached.

4

maximum age

Specifies that caching is valid until the maximum age in seconds. After that, the client must make another request.

five

be sure to double-check

Instructing the server to revalidate the resource if the maximum age has passed.

Always keep static content like images, css, javascript cacheable with an expiration time of 2 to 3 days.

Never keep the expiration date too high.

Dynamic content should only be cached for a few hours.