server/sources/ldapuser.py
branchstable
changeset 5637 b72a838aa109
parent 5604 60a92bf32a18
child 5642 6a90357b9769
--- a/server/sources/ldapuser.py	Sat May 29 10:06:07 2010 +0000
+++ b/server/sources/ldapuser.py	Wed Jun 02 15:55:58 2010 +0000
@@ -33,7 +33,7 @@
 WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 FOR A PARTICULAR PURPOSE.
 """
-
+from __future__ import division
 from base64 import b64decode
 
 from logilab.common.textutils import splitstrip
@@ -158,7 +158,7 @@
         ('cache-life-time',
          {'type' : 'time',
           'default': '2h',
-          'help': 'life time of query cache in minutes (default to two hours).',
+          'help': 'life time of query cache (default to two hours).',
           'group': 'ldap-source', 'level': 3,
           }),
 
@@ -187,9 +187,11 @@
                               for o in self.user_classes]
         self._conn = None
         self._cache = {}
+        # ttlm is in minutes!
         ttlm = time_validator(None, None,
-                              source_config.get('cache-life-time', 2*60))
-        self._query_cache = TimedCache(ttlm)
+                              source_config.get('cache-life-time', 2*60*60)) // 60
+        self._query_cache = TimedCache(max(ttlm, 1))
+        # interval is in seconds !
         self._interval = time_validator(None, None,
                                         source_config.get('synchronization-interval',
                                                24*60*60))
@@ -197,13 +199,15 @@
     def reset_caches(self):
         """method called during test to reset potential source caches"""
         self._cache = {}
-        self._query_cache = TimedCache(2*60)
+        self._query_cache = TimedCache(2*60) # TimedCache is in minutes!
 
     def init(self):
         """method called by the repository once ready to handle request"""
         self.info('ldap init')
-        self.repo.looping_task(self._interval, self.synchronize)
-        self.repo.looping_task(self._query_cache.ttl.seconds/10,
+        # set minimum period of 5min 1s (the additional second is to minimize
+        # resonnance effet)
+        self.repo.looping_task(max(301, self._interval), self.synchronize)
+        self.repo.looping_task(max(7, self._query_cache.ttl.seconds // 10),
                                self._query_cache.clear_expired)
 
     def synchronize(self):