Changeset 537
- Timestamp:
- 10/10/08 13:06:46 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/usermanagerplugin/tracusermanager/api.py
r532 r537 3 3 # Copyright 2008 Optaros, Inc. 4 4 # 5 try:6 import threading7 except ImportError:8 import dummy_threading as threading9 import time10 5 11 6 import traceback … … 487 482 return [] 488 483 489 class CachedSessionAttributeProvider(SessionAttributeProvider):490 CACHE_UPDATE_INTERVAL = 50491 492 def __init__(self):493 self._attribute_cache = {}494 self._attribute_cache_last_update = {}495 self._attribute_cache_lock = threading.RLock()496 497 def _update_cache(self, username, force=False):498 self._attribute_cache_lock.acquire()499 try:500 now = time.time()501 if now > self._attribute_cache_last_update.get(username,0) + CachedSessionAttributeProvider.CACHE_UPDATE_INTERVAL \502 or not self._attribute_cache.has_key(username) \503 or force:504 db = self.env.get_db_cnx()505 cursor = db.cursor()506 cursor.execute("SELECT name, value FROM session_attribute WHERE sid=%s",(username,))507 self._attribute_cache[username] = {}508 for name,value in cursor:509 self._attribute_cache[username][name] = value510 self._attribute_cache_last_update[username] = now511 self.log.debug("Updating SessionAttributeProvider attribute cache for user <%s>"%(username,))512 finally:513 self._attribute_cache_lock.release()514 515 def get_user_attribute(self, username, attribute):516 self._update_cache(username)517 if username in self._attribute_cache:518 return self._attribute_cache[username].get(attribute)519 return None520 521 def set_user_attribute(self, username, attribute, value):522 return_value = super(CachedSessionAttributeProvider, self).set_user_attribute(username, attribute, value)523 self._update_cache(username, force=True)524 return return_value525 526 def delete_user_attribute(self, username, attribute):527 return_value = super(CachedSessionAttributeProvider, self).delete_user_attribute(username, attribute)528 self._update_cache(username, force=True)529 return return_value530 531 484 class EnvironmentFixKnownUsers(Component): 532 485 implements(IEnvironmentSetupParticipant)
Note: See TracChangeset
for help on using the changeset viewer.
