djblets.siteconfig.managers¶
Model and cache management for SiteConfiguration.
- class SiteConfigurationManager(*args, **kwargs)¶
Bases:
Manager
Manages cached instances of a SiteConfiguration.
This provides functions for retrieving the current
SiteConfiguration
instance and working with cache expiration. Consumers are expected to useget_current()
to retrieve their instance, and are also expected to use theSettingsMiddleware
to manage expiration between server processes.- get_current() SiteConfiguration ¶
Return the site configuration for the active site.
Multiple calls to this method for the same
Site
will 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: int) SiteConfiguration ¶
Return the site configuration for a specific site ID.
Multiple calls to this method for the same
Site
will 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() None ¶
Clear the entire SiteConfiguration cache.
The next call to
get_current()
for anySite
will query the database.
- check_expired() None ¶
Check whether any SiteConfigurations have expired.
If a
SiteConfiguration
has 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_reloaded
signal, a newSiteConfiguration
instance 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
SettingsMiddleware
to 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_reloaded
signal is now emitted with a newly-fetched instance if there are any listeners.
- __slotnames__ = []¶