Hi
I tried to execute http request using URLSession and related APIs as shown in the sequence below.
Is it correct behavior that 2nd GET request gets response from cache?
Assumptions
- Set URLCache with disk cache(50MB) and without memory cache to URLSession(configuration:).
- All requests use "useProtocolCachePolicy"
- All response sizes are less than 1KB
Sequence
- Execute GET request
response is cached
- Execute POST/PUT/DELETE request for same url
response code is 200
- Execute GET request for same url
cache response is returned
I expected 2nd GET request (3.) to return response from server since POST/PUT/DELETE request changes server resource.
I have 2 questions.
- Does URLCache supports cache invalidation in case of POST/PUT/DELETE so that subsequent GET requests fetch latest response from server (This behavior is supported in frameworks like OkHttp).
- In case URLCache does not support above, how should I implement cache purge in case of POST/PUT/DELETE?
I tried to use URLCache#removeCachedResponse(for:) api to manually remove cache in case of POST/PUT/DELETE, but didn't work properly (cache was not deleted). Maybe because of https://forums.developer.apple.com/message/298232#298232