Django: Ticket #12063: Ensure SITE_CACHE uses integers as key values <p> Currently <tt>django.contrib.sites.models.SiteManager.get_current</tt> just takes whatever value <tt>SITE_ID</tt> is set to and shoves it into the cache. This leads to strange results if you replace the integer value with a proxy object that implements <tt>__int__()</tt>. </p> <p> Whenever you want to return a different value at runtime (say you want to serve different content depending on the time of day or the hostname), you currently have to clear the cache as you end up with the following <tt>dict</tt>: </p> <pre class="wiki">SITE_CACHE = { &lt;Your proxy object&gt;: &lt;The first Site object ever used&gt;, } </pre><p> The second time Django will just use the cache (as the proxy is equal to itself even if the value returned by <tt>__int__()</tt> changed). </p> <p> Yes, I know altering settings at run time is not really encouraged but being able to proxy SITE_ID and alter the value using middleware is useful when dealing with dynamic subdomains (like and the change is both tiny and backwards-compatible. </p> en-us Django Trac 1.0 patrys Wed, 21 Oct 2009 08:29:25 GMT attachment set <ul> <li><strong>attachment</strong> set to <em>django-site-cache.patch</em> </li> </ul> <p> Same patch in svn diff format </p> Ticket russellm Thu, 04 Feb 2010 13:33:34 GMT status changed; needs_docs, resolution, needs_tests, needs_better_patch set <ul> <li><strong>status</strong> changed from <em>new</em> to <em>closed</em> </li> <li><strong>needs_docs</strong> unset </li> <li><strong>resolution</strong> set to <em>wontfix</em> </li> <li><strong>needs_tests</strong> unset </li> <li><strong>needs_better_patch</strong> unset </li> </ul> <p> I'm not convinced that a dynamic SITE_ID is the right way to tackle this class of problem. I'm going to mark this wontfix; please raise this on django-dev if you want to argue your position. </p> Ticket