Skip to content

Commit 4c297ba

Browse files
committed
Changed settings so that cache keys used by memcached includes the release version, in order to avoid stale and incorrect cache content on new release deployment. Made it easier to pick out cache key composition by normalizing the variable name. Adjusted cache prefix and the composition of some keys to have a unique and consistent cache key prefix.
- Legacy-Id: 14943
1 parent 6844624 commit 4c297ba

7 files changed

Lines changed: 34 additions & 29 deletions

File tree

ietf/checks.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,18 +272,18 @@ def cache_error(msg, errnum):
272272
hint = "Please check that the configured cache backend is available.\n",
273273
id = "datatracker.%s" % errnum,
274274
)
275-
key = "ietf:checks:check_cache"
275+
cache_key = "checks:check_cache"
276276
val = os.urandom(32)
277277
wait = 1
278-
cache.set(key, val, wait)
279-
if not cache.get(key) == val:
278+
cache.set(cache_key, val, wait)
279+
if not cache.get(cache_key) == val:
280280
errors.append(cache_error("Could not get value from cache", "E0014"))
281281
time.sleep(wait+1)
282282
# should have timed out
283-
if cache.get(key) == val:
283+
if cache.get(cache_key) == val:
284284
errors.append(cache_error("Cache value didn't time out", "E0015"))
285-
cache.set(key, val, settings.SESSION_COOKIE_AGE)
286-
if not cache.get(key) == val:
285+
cache.set(cache_key, val, settings.SESSION_COOKIE_AGE)
286+
if not cache.get(cache_key) == val:
287287
errors.append(cache_error("Cache didn't accept session cookie age", "E0016"))
288288
return errors
289289

ietf/doc/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,14 @@ def htmlized(self):
468468
html = ""
469469
if text:
470470
cache = caches['htmlized']
471-
key = name.split('.')[0]
472-
html = cache.get(key)
471+
cache_key = name.split('.')[0]
472+
html = cache.get(cache_key)
473473
if not html:
474474
# The path here has to match the urlpattern for htmlized
475475
# documents in order to produce correct intra-document links
476476
html = rfc2html.markup(text, path=settings.HTMLIZER_URL_PREFIX)
477477
if html:
478-
cache.set(key, html, settings.HTMLIZER_CACHE_TIME)
478+
cache.set(cache_key, html, settings.HTMLIZER_CACHE_TIME)
479479
return html
480480

481481
class Meta:

ietf/doc/views_search.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ def search(request):
204204
if not form.is_valid():
205205
return HttpResponseBadRequest("form not valid: %s" % form.errors)
206206

207-
key = get_search_cache_key(get_params)
208-
results = cache.get(key)
207+
cache_key = get_search_cache_key(get_params)
208+
results = cache.get(cache_key)
209209
if not results:
210210
results = retrieve_search_results(form)
211-
cache.set(key, results)
211+
cache.set(cache_key, results)
212212

213213
results, meta = prepare_document_table(request, results, get_params)
214214
meta['searching'] = True
@@ -242,8 +242,8 @@ def find_unique(n):
242242

243243
return None
244244

245-
def cached_redirect(key, url):
246-
cache.set(key, url, settings.CACHE_MIDDLEWARE_SECONDS)
245+
def cached_redirect(cache_key, url):
246+
cache.set(cache_key, url, settings.CACHE_MIDDLEWARE_SECONDS)
247247
return HttpResponseRedirect(url)
248248

249249
n = name

ietf/doc/views_stats.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ def chart_newrevisiondocevent(request):
124124
def chart_data_newrevisiondocevent(request):
125125
queryargs = request.GET
126126
if queryargs:
127-
key = get_search_cache_key(queryargs)
128-
results = cache.get(key)
127+
cache_key = get_search_cache_key(queryargs)
128+
results = cache.get(cache_key)
129129
if not results:
130130
form = SearchForm(queryargs)
131131
if not form.is_valid():
132132
return HttpResponseBadRequest("form not valid: %s" % form.errors)
133133
results = retrieve_search_results(form)
134134
if results.exists():
135-
cache.set(key, results)
135+
cache.set(cache_key, results)
136136
if results.exists():
137137
data = model_to_timeline_data(DocEvent, doc__in=results, type='new_revision')
138138
else:

ietf/release/views.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import time
2525
time.strptime('1984', '%Y') # we do this to force lib loading, instead of it happening lazily when changelog calls tzparse later
2626

27-
import ietf
2827

2928
def trac_links(text):
3029
# changeset links
@@ -35,8 +34,8 @@ def trac_links(text):
3534

3635

3736
def get_coverage_data():
38-
key = 'ietf:release:get_coverage_data:%s' % ietf.__version__
39-
coverage_data = cache.get(key)
37+
cache_key = 'release:get_coverage_data'
38+
coverage_data = cache.get(cache_key)
4039
if not coverage_data:
4140
coverage_data = {}
4241
if os.path.exists(settings.TEST_COVERAGE_MASTER_FILE):
@@ -46,16 +45,16 @@ def get_coverage_data():
4645
else:
4746
with open(settings.TEST_COVERAGE_MASTER_FILE) as file:
4847
coverage_data = json.load(file)
49-
cache.set(key, coverage_data, 60*60*24)
48+
cache.set(cache_key, coverage_data, 60*60*24)
5049
return coverage_data
5150

5251
def get_changelog_entries():
53-
key = 'ietf:release:get_changelog_entries:%s' % ietf.__version__
54-
log_entries = cache.get(key)
52+
cache_key = 'release:get_changelog_entries'
53+
log_entries = cache.get(cache_key)
5554
if not log_entries:
5655
if os.path.exists(settings.CHANGELOG_PATH):
5756
log_entries = changelog.parse(settings.CHANGELOG_PATH)
58-
cache.set(key, log_entries, 60*60*24)
57+
cache.set(cache_key, log_entries, 60*60*24)
5958
return log_entries
6059

6160
def release(request, version=None):

ietf/settings.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,8 @@ def skip_unreadable_post(record):
616616
'default': {
617617
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
618618
'LOCATION': '127.0.0.1:11211',
619+
'VERSION': __version__,
620+
'KEY_PREFIX': 'ietf',
619621
},
620622
'htmlized': {
621623
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
@@ -1025,9 +1027,13 @@ def skip_unreadable_post(record):
10251027
TEMPLATES[0]['OPTIONS']['loaders'] = loaders
10261028

10271029
CACHES = {
1028-
'default': {
1029-
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
1030-
},
1030+
'default': {
1031+
#'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
1032+
#'LOCATION': '127.0.0.1:11211',
1033+
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
1034+
'VERSION': __version__,
1035+
'KEY_PREFIX': 'ietf:dt',
1036+
},
10311037
'htmlized': {
10321038
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
10331039
#'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',

ietf/stats/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def build_document_stats_url(stats_type_override=Ellipsis, get_overrides={}):
134134

135135
return urlreverse(document_stats, kwargs={ k: v for k, v in kwargs.iteritems() if v is not None }) + generate_query_string(request.GET, get_overrides)
136136

137-
cache_key = ("stats:document:%s:%s" % (stats_type, request.META.get('QUERY_STRING','')))
137+
cache_key = ("stats:document_stats:%s:%s" % (stats_type, request.META.get('QUERY_STRING','')))
138138
data = cache.get(cache_key)
139139
if not data:
140140
names_limit = settings.STATS_NAMES_LIMIT
@@ -766,7 +766,7 @@ def build_meeting_stats_url(number=None, stats_type_override=Ellipsis, get_overr
766766

767767
return urlreverse(meeting_stats, kwargs={ k: v for k, v in kwargs.iteritems() if v is not None }) + generate_query_string(request.GET, get_overrides)
768768

769-
cache_key = "stats:meeting:%s:%s:%s" % (num, stats_type, request.META.get('QUERY_STRING',''))
769+
cache_key = "stats:meeting_stats:%s:%s:%s" % (num, stats_type, request.META.get('QUERY_STRING',''))
770770
data = cache.get(cache_key)
771771
if not data:
772772
names_limit = settings.STATS_NAMES_LIMIT

0 commit comments

Comments
 (0)