Skip to content

Commit

Permalink
fix readme line length
Browse files Browse the repository at this point in the history
  • Loading branch information
Burgyn committed Apr 18, 2024
1 parent 947ecdf commit c4422ea
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,29 @@

## Basic

The Ocelot ETag Caching library adds support for ETag caching to the Ocelot API Gateway. ETag caching is a mechanism that allows a client to cache data and the next time the same data is requested, the client can verify that the data is still up to date. If the data is still current, the server will return a status of `304 Not Modified` and the client will use the cached data. If the data is not up-to-date, the server returns the data and the client caches it.
The Ocelot ETag Caching library adds support for ETag caching to the Ocelot API Gateway.
ETag caching is a mechanism that allows a client to cache data and the next time the same data is requested,
the client can verify that the data is still up to date. If the data is still current, the server will return a status
of `304 Not Modified` and the client will use the cached data. If the data is not up-to-date,
the server returns the data and the client caches it.

The idea is that the server adds two important headers to the response:

- `ETag` - data identifier (randomly generated value)
- `cache-control` - identifier that the data can be cached. Contains only the value `private` (⚠️ beware it must not be `public`, because then the data can remain cached anywhere.) It also does not contain `max-age` because in this case the client would not verify the data on the server (for a given amount of time. Occasionally this may be OK).

If the client (browser) finds these two headers in the response, it adds the `If-None-Match` header with the `ETag` value in the next request to the server with the same path and the server knows if the data is still up to date based on this value. If they are up to date it returns a status of `304 Not Modified` and the client uses the data from the cache.
If the client (browser) finds these two headers in the response, it adds the `If-None-Match` header with the `ETag`
value in the next request to the server with the same path and the server knows if the data is still up to date
based on this value. If they are up to date it returns a status of `304 Not Modified` and the client uses the data from the cache.
**👌 The server does not send the data. This saves resources and bandwidth**

On the client, this works automatically because this behavior is defined in the HTTP specification (no need to do anything).

## Implementation

The implementation is based on Ocelot middleware. All caching will be done in this middleware and nothing will be needed on the service side. The data itself is not cached, but only its identifier (ETag), based on which the data is verified to be up-to-date.
The implementation is based on Ocelot middleware. All caching will be done in this middleware and nothing
will be needed on the service side. The data itself is not cached, but only its identifier (ETag),
based on which the data is verified to be up-to-date.

We use `IOutputCacheStore` to store ETags and invalidate them.

Expand Down

0 comments on commit c4422ea

Please sign in to comment.