mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-10 23:47:55 -05:00
Subreddit._by_name: Set 1 hour cache TTL
In the case of cache outages the values in cache can become out of sync with reality. If a subreddit is created during an outage it will be impossible to access it with Subreddit._by_name until the cache is corrected. Setting a TTL will ensure this happens eventually.
This commit is contained in:
@@ -476,7 +476,11 @@ class Subreddit(Thing, Printable, BaseSite):
|
||||
still_missing = set(srnames) - set(fetched)
|
||||
fetched.update((name, cls.SRNAME_NOTFOUND) for name in still_missing)
|
||||
try:
|
||||
g.gencache.set_multi(fetched, prefix='srid:')
|
||||
g.gencache.set_multi(
|
||||
keys=fetched,
|
||||
prefix='srid:',
|
||||
time=3600,
|
||||
)
|
||||
except MemcachedError:
|
||||
pass
|
||||
|
||||
|
||||
@@ -226,7 +226,10 @@ class ByNameTest(unittest.TestCase):
|
||||
|
||||
self.assertEqual(ret, sr)
|
||||
self.cache.set_multi.assert_called_once_with(
|
||||
{sr.name: sr._id}, prefix="srid:")
|
||||
keys={sr.name: sr._id},
|
||||
prefix="srid:",
|
||||
time=3600,
|
||||
)
|
||||
|
||||
def testCacheNegativeResults(self):
|
||||
self.cache.get_multi.return_value = {}
|
||||
@@ -237,7 +240,10 @@ class ByNameTest(unittest.TestCase):
|
||||
Subreddit._by_name("doesnotexist")
|
||||
|
||||
self.cache.set_multi.assert_called_once_with(
|
||||
{"doesnotexist": Subreddit.SRNAME_NOTFOUND}, prefix="srid:")
|
||||
keys={"doesnotexist": Subreddit.SRNAME_NOTFOUND},
|
||||
prefix="srid:",
|
||||
time=3600,
|
||||
)
|
||||
|
||||
def testExcludeNegativeLookups(self):
|
||||
self.cache.get_multi.return_value = {"doesnotexist": Subreddit.SRNAME_NOTFOUND}
|
||||
|
||||
Reference in New Issue
Block a user