Skip to content

Commit bbde012

Browse files
committed
Move the app reverse cache key generation into an ApplicationContent class method, similar to closest_match
1 parent e45c44f commit bbde012

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

feincms/content/application/models.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,11 @@ def app_reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None,
7070
appconfig = extra_context.get('app_config', {})
7171
urlconf = appconfig.get('urlconf_path', urlconf)
7272

73-
cache_generation = cache.get(APP_REVERSE_CACHE_GENERATION_KEY)
74-
if cache_generation is None:
75-
# This might never happen. Still, better be safe than sorry.
76-
cache_generation = cycle_app_reverse_cache()
77-
78-
cache_key = 'FEINCMS:%s:APPCONTENT:L%s:U%s:G%s' % (
79-
getattr(settings, 'SITE_ID', 0),
80-
get_language(),
81-
urlconf,
82-
cache_generation)
83-
73+
appcontent_class = ApplicationContent._feincms_content_models[0]
74+
cache_key = appcontent_class.app_reverse_cache_key(urlconf)
8475
url_prefix = cache.get(cache_key)
8576

8677
if url_prefix is None:
87-
appcontent_class = ApplicationContent._feincms_content_models[0]
8878
content = appcontent_class.closest_match(urlconf)
8979

9080
if content is not None:
@@ -379,6 +369,19 @@ def _update_response_headers(self, request, response, headers):
379369
if len(lm_list) > 0:
380370
response['Expires'] = http_date(mktime(min(lm_list)))
381371

372+
@classmethod
373+
def app_reverse_cache_key(self, urlconf_path, **kwargs):
374+
cache_generation = cache.get(APP_REVERSE_CACHE_GENERATION_KEY)
375+
if cache_generation is None:
376+
# This might never happen. Still, better be safe than sorry.
377+
cache_generation = cycle_app_reverse_cache()
378+
379+
return 'FEINCMS:%s:APPCONTENT:L%s:U%s:G%s' % (
380+
getattr(settings, 'SITE_ID', 0),
381+
get_language(),
382+
urlconf_path,
383+
cache_generation)
384+
382385
@classmethod
383386
def closest_match(cls, urlconf_path):
384387
page_class = cls.parent.field.rel.to

0 commit comments

Comments
 (0)