Cache

Diagrammes de séquence

ETag

blockdiag Client Server GET /foo 200 OK Etag: "abc" GET /foo If-none-match: "abc" 304 Not Modified GET /foo If-none-match: "abc" 200 OK Etag: "cde" Resource changes

Premier échange

blockdiag Client Cache Server store entity with etag GET /foo GET /foo 200 OK Etag: "abc" 200 OK Etag: "abc"

Échange suivant

blockdiag Client Cache Server retrieve entity from cache GET /foo GET /foo If-none-match: "abc" 304 Not Modified 200 OK Etag: "abc"

Après modification

blockdiag Client Cache Server update entity and etag GET /foo GET /foo If-none-match: "abc" 200 OK Etag: "cde" 200 OK Etag: "cde"

Durée de validité

blockdiag Client Cache Server store entity with etag and max-age cached entity is up-to-date cached entity has expired update max-age retrieve entity from cache GET /foo GET /foo 200 OK Etag: "abc" Cache-control: max-age=10 200 OK Etag: "abc" GET /foo 200 OK Etag: "abc" GET /foo GET /foo If-none-match: "abc" 304 Not Modified Cache-control: max-age=10 200 OK Etag: "abc" 1s 20s

Utilisation avec Apache Components

Installation maven

CacheConfig cacheConfig = CacheConfig.custom()
        .setMaxCacheEntries(1000)
        .setMaxObjectSize(8192)
        .build();
CloseableHttpClient cachingClient = CachingHttpClients.custom()
        .setCacheConfig(cacheConfig)
        .build();