From 5a0ca3c07a85e3503da77fde368b14bb253656f9 Mon Sep 17 00:00:00 2001 From: Randy Duodu Date: Wed, 18 Dec 2024 13:47:39 +0000 Subject: [PATCH] Updated notes on using a ``cache`` instance when initializing ``OAuth``. (#693) * Updated notes on using a ``cache`` instance when initializing ``OAuth``. --- docs/client/flask.rst | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/docs/client/flask.rst b/docs/client/flask.rst index 76e21d5c..d8436e36 100644 --- a/docs/client/flask.rst +++ b/docs/client/flask.rst @@ -98,9 +98,46 @@ system. When initializing ``OAuth``, you can pass an ``cache`` instance:: A ``cache`` instance MUST have methods: +- ``.delete(key)`` - ``.get(key)`` - ``.set(key, value, expires=None)`` +An example of a ``cache`` instance can be: + +.. code-block:: python + + from flask import Flask + + class OAuthCache: + + def __init__(self, app: Flask) -> None: + """Initialize the AuthCache.""" + self.app = app + + def delete(self, key: str) -> None: + """ + Delete a cache entry. + + :param key: Unique identifier for the cache entry. + """ + + def get(self, key: str) -> str | None: + """ + Retrieve a value from the cache. + + :param key: Unique identifier for the cache entry. + :return: Retrieved value or None if not found or expired. + """ + + def set(self, key: str, value: str, expires: int | None = None) -> None: + """ + Set a value in the cache with optional expiration. + + :param key: Unique identifier for the cache entry. + :param value: Value to be stored. + :param expires: Expiration time in seconds. Defaults to None (no expiration). + """ + Routes for Authorization ------------------------