~/ learn/ comp-348/ cards/ Caching: freshness, revalidation, and ResponseCache
1 of 5

Install a JVM-wide cache, then opt one connection out of it

Install a JVM-wide cache, then opt one connection out of it

Answer

ResponseCache.setDefault(new DiskCache()); URLConnection conn = url.openConnection(); conn.setUseCaches(false); try (InputStream in = conn.getInputStream()) { in.transferTo(System.out); }

setDefault installs one cache for the whole JVM, exactly as CookieHandler.setDefault installs one cookie store. setUseCaches(false) excuses a single connection from it, and being a configuration setter it must run before the first read or it throws IllegalStateException.

Harold 4e ch7 §Caches; RFC 7234 §5.2 Cache-Control; §4.3 Validation

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/0ff32b1b-77af-4c9c-b9de-c75706a817b7/flashcard utf-8 LF