Use pyams_cache cache handler interface
authorThierry Florac <thierry.florac@onf.fr>
Wed, 07 Jun 2017 09:31:23 +0200
changeset 10 7dea2cd0fa8a
parent 9 cfac2a5b97bc
child 11 09387489ec24
Use pyams_cache cache handler interface
src/pyams_notify/views/notification.py
--- a/src/pyams_notify/views/notification.py	Wed Jun 07 09:30:54 2017 +0200
+++ b/src/pyams_notify/views/notification.py	Wed Jun 07 09:31:23 2017 +0200
@@ -15,16 +15,14 @@
 
 # import standard library
 import pickle
-try:
-    import pylibmc
-except ImportError:
-    pylibmc = None
 
 # import interfaces
-from pyams_notify.interfaces import MEMCACHED_QUEUE_KEY
+from pyams_cache.interfaces import ICacheHandler
+from pyams_notify.interfaces import CACHE_QUEUE_KEY, CACHE_CONFIGURATION_KEY
 from pyams_skin.layer import IPyAMSLayer
 
 # import packages
+from pyams_cache.cache import get_cache_handler
 from pyramid.view import view_config
 
 
@@ -42,16 +40,16 @@
         self.context = request.context
 
     @property
-    def memcached_server(self):
-        return self.request.registry.settings.get('pyams_notify_ws.memcached_server')
+    def cache_server(self):
+        return self.request.registry.settings.get(CACHE_CONFIGURATION_KEY)
 
     def __call__(self):
-        if pylibmc is None:
-            return ()
-        server = self.memcached_server
+        server = self.cache_server
         if server is not None:
-            client = pylibmc.Client([server])
-            notifications = client.get(MEMCACHED_QUEUE_KEY)
+            client = get_cache_handler(server, ICacheHandler)
+            if client is None:
+                return ()
+            notifications = client.get(CACHE_QUEUE_KEY)
             if notifications is None:
                 return ()
             else: