Skip to content

mrblrrd/okhttp-cache-control-playground

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Okhttp Cache-Control Playground

Repository for experiments with cache implementation in okhttp. Made public to illustrate this question.

Cache-Control: no-cache

  1. Make GET request with no-cache.

Step 1

  1. Server responds 200 and returns Cache-Control: private with ETag: W/qwerty.

Step 2

  1. We can verify this using proxy.

Step 3

  1. After this the response goes into the cache as expected.

Step 4.1 Step 4.2

  1. Make GET request with no-cache again. It will not be sent as a conditional request. There is no If-None-Match header added and therefore no 304 response.

Step 5

No Cache-Control header

  1. Make GET request with missing Cache-Control header.

Step 6

  1. And now we see a conditional request.

Step 7

Observed Behavior

  1. no-cache in okhttp never hits the cache.
  2. Missing Cache-Control allows to use a private cache and not read the response body.

How to Run

There are prebuilt binaries

# Client Android App
adb install android-app-debug.apk
# REST API String App
java -jar spring-app-fat.jar

# Requires Java 21
JAVA_HOME="$JAVA_HOME_21" java -jar spring-app-fat.jar

Or you can build them from source

cd android/
JAVA_HOME="$JAVA_HOME_17" ./gradlew app:assemble
adb install app/build/outputs/apk/debug/app-debug.apk
cd spring/
JAVA_HOME="$JAVA_HOME_21" ./mvnw clean spring-boot:run

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors