Simplify ForwardingCacheBackend to reduce state storage.

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

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.

Commits

Files