title: How to get Django Admin to cache select options on inlines?
body: <p>Using Django 1.11, Python 3.6</p>
  
  <p>I'm having no luck whatsoever with this. I'm trying to optimise a slow Django Admin page which is making a lot of duplicate SQL queries due to a lot of <code>select</code> dropdowns and multiple inlines.</p>
  
  <p>I've tried using the <code>cacheops</code> library and a Redis store, but nothing gets cached at all, even if I set <em>everything</em> to cache automatically with <code>'*.*': {'ops': 'all', 'timeout': 60*60},</code>. I'm assuming this may be because the Admin seems to bypass normal Django ORM objects.</p>
  
  <p>Speaking of which, I tried just implementing a bespoke objects manager that caches using the <code>cachetools</code> library's TTLCache class:</p>
  
  <pre><code>from django.db import models
  from cachetools import TTLCache, cached
  
  cache = TTLCache(maxsize=100, ttl=3600)
  
  class CacheManager(models.Manager):
      @cached(cache)
      def get(self, *args, **kwargs):
          print("Caching get. args: %r. kwargs: %r" % (args, kwargs))
          return super(CacheManager, self).get(*args, **kwargs)
  
      @cached(cache)
      def all(self, *args, **kwargs):
          print("Caching all. args: %r. kwargs: %r" % (args, kwargs))
          return super(CacheManager, self).all(*args, **kwargs)
  
      @cached(cache)
      def filter(self, *args, **kwargs):
          print("Caching filter. args: %r. kwargs: %r" % (args, kwargs))
          return super(CacheManager, self).filter(*args, **kwargs)
  
      @cached(cache)
      def order_by(self, *args, **kwargs):
          print("Caching order_by. args: %r. kwargs: %r" % (args, kwargs))
          value = super(CacheManager, self).order_by(*args, **kwargs)
          print(value)
          return value
  
      @cached(cache)
      def first(self, *args, **kwargs):
          print("Caching first. args: %r. kwargs: %r" % (args, kwargs))
          return super(CacheManager, self).first(*args, **kwargs)
  </code></pre>
  
  <p>then my model class:</p>
  
  <pre><code>class Role(models.Model):
      date_added = models.DateTimeField(auto_now_add=True)
      date_modified = models.DateTimeField(auto_now=True)
      name = models.CharField(max_length=100, unique=True)
  
      objects = CacheManager()
  
      class Admin:
          manager = CacheManager()
  </code></pre>
  
  <p>This doesn't do anything either. At first I thought it was down to admin not using the bespoke objects manager, but I found a comment on StackOverflow that adding the Admin class with the manager is supposed to fix that - but it clearly doesn't in this case, because when loading an admin page that has a Role <code>select</code> I get this in the log:</p>
  
  <p>2018-06-04 11:49:06,350 [DEBUG] django.db.backends: (0.003) QUERY = 'SELECT [cms_role].[id], [cms_role].[date_added], [cms_role].[date_modified], [cms_role].[name] FROM [cms_role] ORDER BY [cms_role].[name] ASC' - PARAMS = (); args=()</p>
  
  <p>** 20 more repeats of this skipped **</p>
  
  <p>2018-06-04 11:49:07,572 [DEBUG] django.db.backends: (0.002) QUERY = 'SELECT [cms_role].[id], [cms_role].[date_added], [cms_role].[date_modified], [cms_role].[name] FROM [cms_role] ORDER BY [cms_role].[name] ASC' - PARAMS = (); args=()</p>
  
  <p>That's over a second of repeated SQL queries! How do I stop it from doing this??</p>