Caching

We use the Django standard cache framework, and recommend the use of Redis in a production environment.

The cache is configured in portal.conf.

Keys

These are keys that we use in the caching framework.

_cache_key(‘GroupsWithIngestRights’, self.instance.user)

This key is for use for caching which groups have ingest rights for particular user.

_cache_key(‘UsersGroupsAll’, self.instance.user)

This key caches all the groups that a user is a member of.

cache.set(cache_key_user(‘UsersTheme’, request.user), theme)

Caches a users particular theme.

cache.set(cache_key_user(‘UsersThemeCSSFile’, request.user), cssfile)

Caches the cssfile a user uses.

cache.set(cache_key_template(template_name), t.template_string)

Caches template strings from the database.

cache.set(cache_key_user(“UserObjectByID”, user_id), _user_object)

Caches the user object ByID. - Invalidate in updating the user.

cache.set(‘logoObj’, logoObj, 30000)

Caches the logo used on the site.

cache.set(cache_key_user(‘UsersRoles’, user), logged_in_roles)

The roles a user has. Cachekey is deleted on logout.

cache.set(cache_key_user(“UserProfile”, user), _user_profile)

This is set as part of the utils.cache.cache_get_users_profile(user) function. It is deleted on change of UserProfile model for that user instance.

Template loader caching

Caching is used so that the template files are not loaded from the disk each time they are rendered. It is configured so that this doesn’t happen if DEBUG is set to true in the configuration file. Make sure on high volume sites that the /opt/cantemo/portal/portal_themes/ directory is still on a fast disk system.

Middleware caching

Portal is not configured to use much middleware caching as we have found that it is not granular enough when dealing with constantly changing assets and items. However there are several places where it is used, particular on pages that don’t change that often such as the Javascript translation files.

Template fragmentation caching

Parts of individual templates are cached as needed. If you are implementing your own theme please make sure that the cache keys used take into account that not everybody sees the page the same and so valid keys could be in the form of:

{% load cache %}
{% cache 500 LANGUAGE_CODE THEME request.user %}
{% endcache %}

This will cache but taking into account the user, their language settings and the theme they are using. It will timeout in 500 seconds.