def _set_update_date(self, session): sess_data = json.loads(session.serialized_data) if not sess_data.get('fixed_lifetime'): logger.debug("Updating session update date") session.update_date = datetime.now(pytz.utc) else: logger.debug("Not updating update date of " \ "session with fixed lifetime")
def _get_cached_session(self, session_id): logger.debug("Getting session from memcached") str_sess_id = session_id.encode('utf8') session = None try: session = self.mem_cache.get(str_sess_id) except Exception, e: logger.info("Session %s not found in memcached: %s", str_sess_id, e)
def _save_session_to_cache(self, session): str_sess_id = session.session_id.encode('utf8') expire_sec = settings.session_valid_minutes * 60 expire_dt = session.update_date + timedelta(seconds=expire_sec) curr_dt = datetime.now(pytz.utc) if expire_dt <= curr_dt: logger.debug("Session %s expired. Not saving to cache", session.session_id) else: expire_delta = expire_dt - curr_dt # Workaround for excluding creation non expiring sessions cache_expire_sec = expire_delta.seconds if expire_delta.seconds else 1 logger.debug("Saving session %s to cache. Current date: %s. " \ "Session update date: %s. " \ "Session in cache expired after %s seconds", session.session_id, curr_dt, session.update_date, expire_delta.seconds) self.mem_cache.set(str_sess_id, session, time=cache_expire_sec)