From e72926647459186bbfdc850e9dd78867126de33c Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 8 Jul 2015 00:46:08 +0200 Subject: [PATCH 2/3] decorators: add SessionCache to store cache of values in session --- src/authentic2/decorators.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/authentic2/decorators.py b/src/authentic2/decorators.py index 3006520..8132c6f 100644 --- a/src/authentic2/decorators.py +++ b/src/authentic2/decorators.py @@ -217,6 +217,17 @@ class DjangoCache(SimpleDictionnaryCacheMixin, CacheDecoratorBase): if self.get(key) == value: self.delete(key) + +class SessionCache(SimpleDictionnaryCacheMixin, CacheDecoratorBase): + @property + def cache(self): + request = middleware.StoreRequestMiddleware.get_request() + if not request: + return {} + # create a cache dictionary on the request + return request.session.setdefault(self.__class__.__name__, {}) + + @contextmanager def errorcollector(error_dict): try: -- 2.1.4