Simplify ForwardingCacheBackend to reduce state storage.

Review Request #13449 — Created Dec. 5, 2023 and submitted

Information

Djblets
release-3.x

Reviewers

When ForwardingCacheBackend was first created, it had to work around
some assumptions in Django where a cache backend could be created but
then never replaced.

Modern Django manages cache backends through a mutable registry,
removing much of the need for ForwardingCacheBackend. However, it's
still a useful API.

In an effort to keep the logic simple, and to remove any
threading-related requirements in the implementation, this change
updates the backend to just look up the named backend on demand, rather
than storing an instance of it. This should avoid any issues where a
stale backend could ever be in use, and allows Django's connection
management to handle any threading responsibility.

There's also a fix in the code for applying siteconfig settings. The old
code assumed that django.core.cache.cache was an instance of the
backend, but it's not anymore. So instead, we now optimistically call
the function we need on it, ignoring any attribute errors if not found.

All Djblets and Review Board unit tests pass.

Tested this with a local server. Verified that when I changed settings,
the cache updated.

Summary ID
Simplify ForwardingCacheBackend to reduce state storage.
When `ForwardingCacheBackend` was first created, it had to work around some assumptions in Django where a cache backend could be created but then never replaced. Modern Django manages cache backends through a mutable registry, removing much of the need for `ForwardingCacheBackend`. However, it's still a useful API. In an effort to keep the logic simple, and to remove any threading-related requirements in the implementation, this change updates the backend to just look up the named backend on demand, rather than storing an instance of it. This should avoid any issues where a stale backend could ever be in use, and allows Django's connection management to handle any threading responsibility. There's also a fix in the code for applying siteconfig settings. The old code assumed that `django.core.cache.cache` was an instance of the backend, but it's not anymore. So instead, we now optimistically call the function we need on it, ignoring any attribute errors if not found.
bdd536f12f01356f8f5abf2f0b9a590277e8df4d
david
  1. Ship It!
  2. 
      
maubin
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-3.x (bfd5811)
Loading...