From mboxrd@z Thu Jan 1 00:00:00 1970 From: cgit at cryptocrack.de (Lukas Fleischer) Date: Thu, 06 Feb 2014 22:07:51 +0100 Subject: [PATCH 1/2] Skip cache slot when time-to-live is zero In-Reply-To: References: <1391593564-10662-1-git-send-email-cgit@cryptocrack.de> <1391593564-10662-2-git-send-email-cgit@cryptocrack.de> Message-ID: <20140206210751.1827.10130@typhoon.lan> On Thu, 06 Feb 2014 at 20:52:46, Jason A. Donenfeld wrote: > On Wed, Feb 5, 2014 at 10:46 AM, Lukas Fleischer wrote: > > > > /* If the cache is disabled, just generate the content */ > > - if (size <= 0) { > > + if (size <= 0 || ttl == 0) { > > fn(); > > return 0; > > } > > > Apparently we already special case ttl for < 0: > > /* Check if the slot has expired */ > static int is_expired(struct cache_slot *slot) > { > if (slot->ttl < 0) > return 0; > else > return slot->cache_st.st_mtime + slot->ttl * 60 < > time(NULL); > } > > What should our behavior be for consistency? This is different. -1 means "never expire". 0 means "always expire". We cannot add the 0 special case to is_expired(), though, because that would mean we would update and write the cache file to disk on every request which seems to be a bad idea (actually, that is what already happens now without having a special case).