Skip to content

Commit

Permalink
Combined the various cache duration settings in a new CMS_CACHE_DURAT…
Browse files Browse the repository at this point in the history
…IONS settings.
  • Loading branch information
jezdez committed Feb 24, 2011
1 parent 5bde4ba commit 0621c9b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cms/cache/permissions.py
Expand Up @@ -27,7 +27,7 @@ def set_permission_cache(user, key, value):
all_keys.append(cache_key)
if not key in permission_cache_keys:
permission_cache_keys.append(key)
cache.set(cache_key, value, settings.CMS_PERMISSION_CACHE_DURATION)
cache.set(cache_key, value, settings.CMS_CACHE_DURATIONS['permissions'])

def clear_user_permission_cache(user):
"""
Expand Down
16 changes: 8 additions & 8 deletions cms/conf/global_settings.py
Expand Up @@ -25,11 +25,17 @@
# Whether to enable permissions.
CMS_PERMISSION = False

# Defines how long user permissions should be cached
CMS_PERMISSION_CACHE_DURATION = 600
# Decides if pages without any view restrictions are public by default, or staff only
CMS_PUBLIC_FOR = 'all' # or 'staff'

CMS_CACHE_DURATIONS = {
# Menu cache duration
'menus': getattr(settings, 'MENU_CACHE_DURATION', 60 * 60),
# Defines how long page content should be cached
'content': getattr(settings, 'CMS_CONTENT_CACHE_DURATION', 60),
# Defines how long user permissions should be cached
'permissions': 60 * 60,
}

# Show the publication date field in the admin, allows for future dating
# Changing this from True to False could cause some weirdness. If that is required,
Expand Down Expand Up @@ -85,9 +91,6 @@
# 3:['en'],}
CMS_SITE_LANGUAGES = {}

# Defines how long page content should be cached, including navigation
CMS_CONTENT_CACHE_DURATION = 60

CMS_SITE_CHOICES_CACHE_KEY = 'CMS:site_choices'
CMS_PAGE_CHOICES_CACHE_KEY = 'CMS:page_choices'

Expand Down Expand Up @@ -115,6 +118,3 @@

# Cache prefix so one can deploy several sites on one cache server
CMS_CACHE_PREFIX = 'cms-'

# Menu cache duration
MENU_CACHE_DURATION = 60 * 60
4 changes: 2 additions & 2 deletions cms/templatetags/cms_tags.py
Expand Up @@ -111,7 +111,7 @@ def get_context(self, context, page_lookup, lang, site):
page = _get_page_by_untyped_arg(page_lookup, request, site_id)
if page:
url = page.get_absolute_url(language=lang)
cache.set(cache_key, url, settings.CMS_CONTENT_CACHE_DURATION)
cache.set(cache_key, url, settings.CMS_CACHE_DURATIONS['content'])
if url:
return {'content': url}
return {'content': ''}
Expand Down Expand Up @@ -349,7 +349,7 @@ def _show_placeholder_for_page(context, placeholder_name, page_lookup, lang=None
content = "".join(c)

if cache_result:
cache.set(cache_key, content, settings.CMS_CONTENT_CACHE_DURATION)
cache.set(cache_key, content, settings.CMS_CACHE_DURATIONS['content'])

if content:
return {'content': mark_safe(content)}
Expand Down
24 changes: 20 additions & 4 deletions docs/getting_started/configuration.rst
Expand Up @@ -438,20 +438,36 @@ To access these fields in the template use::
...
</head>

CMS_CONTENT_CACHE_DURATION
==========================
CMS_CACHE_DURATIONS
===================

This dictionary carries the varios cache duration settings.

``'content'``
-------------

Default: ``60``

Cache expiration (in seconds) for ``show_placeholder`` and ``page_url`` template tags.

MENU_CACHE_DURATION
===================
.. note:: This settings was previously called ``CMS_CONTENT_CACHE_DURATION``

``'menus'``
-----------

Default: ``3600``

Cache expiration (in seconds) for the menu tree.

.. note:: This settings was previously called ``MENU_CACHE_DURATION``

``'permissions'``
-----------------

Default: ``3600``

Cache expiration (in seconds) for view and other permissions.

CMS_CACHE_PREFIX
================

Expand Down
3 changes: 1 addition & 2 deletions menus/menu_pool.py
Expand Up @@ -146,8 +146,7 @@ def _build_nodes(self, request, site_id):
nodes = self.menus[menu_class_name].get_nodes(request)
# nodes is a list of navigation nodes (page tree in cms + others)
final_nodes += _build_nodes_inner_for_one_menu(nodes, menu_class_name)
duration = getattr(settings, "MENU_CACHE_DURATION", 60*60)
cache.set(key, final_nodes, duration)
cache.set(key, final_nodes, settings.CMS_CACHE_DURATIONS['menus'])
# We need to have a list of the cache keys for languages and sites that
# span several processes - so we follow the Django way and share through
# the database. It's still cheaper than recomputing every time!
Expand Down
6 changes: 5 additions & 1 deletion tests/project/settings.py
Expand Up @@ -168,8 +168,12 @@
CMS_SOFTROOT = True
CMS_MODERATOR = True
CMS_PERMISSION = True
CMS_PERMISSION_CACHE_DURATION = 0
CMS_PUBLIC_FOR = 'all'
CMS_CACHE_DURATIONS = {
'menus': 0,
'content': 0,
'permissions': 0,
}
CMS_REDIRECTS = True
CMS_SEO_FIELDS = True
CMS_FLAT_URLS = False
Expand Down

0 comments on commit 0621c9b

Please sign in to comment.