djblets.siteconfig.managers¶
Model and cache management for SiteConfiguration.
- class SiteConfigurationManager(*args, **kwargs)[source]¶
Manages cached instances of a SiteConfiguration.
This provides functions for retrieving the current
SiteConfigurationinstance and working with cache expiration. Consumers are expected to useget_current()to retrieve their instance, and are also expected to use theSettingsMiddlewareto manage expiration between server processes.- get_current()[source]¶
Return the site configuration for the active site.
Multiple calls to this method for the same
Sitewill return the same instance, as long as the old instance has not expired. Callers should not store the result of this method, as it may not be valid for long.- Returns
The current site configuration for the active site.
- Return type
- Raises
django.core.exceptions.ImproperlyConfigured – Site information wasn’t configured in Django.
- get_for_site_id(site_id)[source]¶
Return the site configuration for a specific site ID.
Multiple calls to this method for the same
Sitewill return the same instance, as long as the old instance has not expired. Callers should not store the result of this method, as it may not be valid for long.- Parameters
site (int) – The ID of the site to retrieve the configuration for.
- Returns
The current site configuration for the specified site.
- Return type
- clear_cache()[source]¶
Clear the entire SiteConfiguration cache.
The next call to
get_current()for anySitewill query the database.
- check_expired()[source]¶
Check whether any SiteConfigurations have expired.
If a
SiteConfigurationhas expired (another process/server has saved a more recent version), this method will expire the cache for the old version.If there are any listeners for the
siteconfig_reloadedsignal, a newSiteConfigurationinstance will be immediately loaded and the signal will fire. Otherwise, a new instance will not be loaded right away.This should be called on each HTTP request. It’s recommended that consumers use
SettingsMiddlewareto do this. It can also be called manually for long-living processes that aren’t bound to HTTP requests.Changed in version 1.0.3: The
siteconfig_reloadedsignal is now emitted with a newly-fetched instance if there are any listeners.