• 
      

    Add support for Django 1.7+'s caches

    Review Request #8721 — Created Feb. 6, 2017 and discarded

    Information

    Djblets
    release-0.10.x

    Reviewers

    In Django 1.7, there's a new caches object which supplants the old
    get_cache method. This change adds support for that.

    Ran Review Board unit tests with log capture disabled. Saw that the
    RemovedInDjango19 warnings disappeared.

    Description From Last Updated

    This still happens in Django 1.7+, just in a different way. Here's the relevant code from django/core/cache/__init__.py: def close_caches(**kwargs): # …

    chipx86chipx86
    reviewbot
    1. Tool: Pyflakes
      Processed Files:
          djblets/cache/forwarding_backend.py
      
      
      
      Tool: PEP8 Style Checker
      Processed Files:
          djblets/cache/forwarding_backend.py
      
      
    2. 
        
    chipx86
    1. 
        
    2. djblets/cache/forwarding_backend.py (Diff revision 1)
       
       
       
       
       
      Show all issues

      This still happens in Django 1.7+, just in a different way. Here's the relevant code from django/core/cache/__init__.py:

      def close_caches(**kwargs):
          # Some caches -- python-memcached in particular -- need to do a cleanup at the
          # end of a request cycle. If not implemented in a particular backend
          # cache.close is a no-op
          for cache in caches.all():
              cache.close()
      signals.request_finished.connect(close_caches)
      

      So that becomes more tricky... Kinda thinking we might need to disconnect that handler and then connect our own that skips this backend (maybe by storing a flag on the forwarder saying "Ignore the close!", and set before close_caches(), unset after).

      1. We also should have a unit test for this. (Sorry I didn't have one before.)

      2. Reading through the code in django, and the change that introduced this stuff in djblets, I think it's actually much simpler. The old code in django had a single cache backend shared across all threads, whereas now the caches are thread-local. We could therefore simplify this backend for the 1.7+ case to just fetch the cache from caches and then not call close() on the forwarded backend, since the request_finished handler will close both the forwarding and forwarded backends.

        Care to double-check my reasoning?

    3. 
        
    david
    Review request changed
    Status:
    Discarded