Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/70.removed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**`BackendProxy.get_backend()` and `BackendProxy.set_backend()` are removed.**
They had emitted a `DeprecationWarning` since 0.3.0. Call `BackendProxy.get()`
and `BackendProxy.set(backend)` instead.
37 changes: 0 additions & 37 deletions fastapi_cachex/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

import threading
import warnings
from logging import getLogger
from typing import TYPE_CHECKING
from typing import ClassVar
Expand Down Expand Up @@ -110,42 +109,6 @@ class BackendProxy(ProxyBase[BaseCacheBackend]):

_not_set_error = BackendNotFoundError

@staticmethod
def get_backend() -> BaseCacheBackend:
"""Get the current backend instance.

.. deprecated:: 0.3.0
Use :meth:`get` instead. Will be removed in version 0.4.0.

Returns:
The current backend instance
"""
warnings.warn(
"get_backend() is deprecated, use get() instead. "
"Will be removed in version 0.4.0.",
DeprecationWarning,
stacklevel=2,
)
return BackendProxy.get()

@staticmethod
def set_backend(backend: BaseCacheBackend | None) -> None:
"""Set the backend instance.

.. deprecated:: 0.3.0
Use :meth:`set` instead. Will be removed in version 0.4.0.

Args:
backend: The backend instance to set, or None to clear
"""
warnings.warn(
"set_backend() is deprecated, use set() instead. "
"Will be removed in version 0.4.0.",
DeprecationWarning,
stacklevel=2,
)
BackendProxy.set(backend)


def get_backend_or_fallback() -> BaseCacheBackend:
"""Return the configured backend, registering a `MemoryBackend` if none is.
Expand Down
25 changes: 0 additions & 25 deletions tests/test_proxybackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,31 +117,6 @@ def test_backend_proxy_cannot_be_instantiated():
BackendProxy()


def test_get_backend_alias_warns_and_delegates():
"""The 0.3.0 deprecation shims stay callable until 0.4.0 removes them."""
backend = MemoryBackend()
BackendProxy.set(backend)

with pytest.warns(DeprecationWarning, match="get_backend\\(\\) is deprecated"):
assert BackendProxy.get_backend() is backend


def test_set_backend_alias_warns_and_delegates():
"""Same for the setter, including clearing with `None`."""
backend = MemoryBackend()

with pytest.warns(DeprecationWarning, match="set_backend\\(\\) is deprecated"):
BackendProxy.set_backend(backend)

assert BackendProxy.get() is backend

with pytest.warns(DeprecationWarning, match="set_backend\\(\\) is deprecated"):
BackendProxy.set_backend(None)

with pytest.raises(BackendNotFoundError):
BackendProxy.get()


@pytest.mark.parametrize(
"proxy", [CacheManagerProxy, SessionManagerProxy, StateManagerProxy]
)
Expand Down
Loading