MemCache
This commit is contained in:
parent
1c6f8b772d
commit
32205b9a7c
@ -3,6 +3,7 @@ import time
|
||||
from datetime import datetime
|
||||
import Queue
|
||||
import signal
|
||||
import Cache
|
||||
|
||||
import lib.settings as settings
|
||||
|
||||
@ -19,8 +20,7 @@ class DBInterface():
|
||||
self.q = Queue.Queue()
|
||||
self.queueclock = None
|
||||
|
||||
self.usercache = {}
|
||||
self.clearusercache()
|
||||
self.cache = Cache.Cache()
|
||||
|
||||
self.nextStatsUpdate = 0
|
||||
|
||||
@ -67,11 +67,6 @@ class DBInterface():
|
||||
return DB_None.DB_None()
|
||||
|
||||
|
||||
def clearusercache(self):
|
||||
log.debug("DBInterface.clearusercache called")
|
||||
self.usercache = {}
|
||||
self.usercacheclock = reactor.callLater(settings.DB_USERCACHE_TIME , self.clearusercache)
|
||||
|
||||
def scheduleImport(self):
|
||||
# This schedule's the Import
|
||||
if settings.DATABASE_DRIVER == "sqlite":
|
||||
@ -163,19 +158,16 @@ class DBInterface():
|
||||
# Force username and password to be strings
|
||||
username = str(username)
|
||||
password = str(password)
|
||||
wid = username + ":-:" + password
|
||||
|
||||
if wid in self.usercache:
|
||||
if not settings.USERS_CHECK_PASSWORD and self.user_exists(username):
|
||||
return True
|
||||
elif not settings.USERS_CHECK_PASSWORD and self.user_exists(username):
|
||||
self.usercache[wid] = 1
|
||||
elif self.cache.get(username) == password:
|
||||
return True
|
||||
elif self.dbi.check_password(username, password):
|
||||
self.usercache[wid] = 1
|
||||
self.cache.set(username, password)
|
||||
return True
|
||||
elif settings.USERS_AUTOADD == True:
|
||||
self.insert_user(username, password)
|
||||
self.usercache[wid] = 1
|
||||
self.cache.set(username, password)
|
||||
return True
|
||||
|
||||
log.info("Authentication for %s failed" % username)
|
||||
@ -188,6 +180,8 @@ class DBInterface():
|
||||
return self.dbi.get_user(id)
|
||||
|
||||
def user_exists(self, username):
|
||||
if self.cache.get(username) is not None:
|
||||
return True
|
||||
user = self.dbi.get_user(username)
|
||||
return user is not None
|
||||
|
||||
@ -195,11 +189,13 @@ class DBInterface():
|
||||
return self.dbi.insert_user(username, password)
|
||||
|
||||
def delete_user(self, username):
|
||||
self.mc.delete(username)
|
||||
self.usercache = {}
|
||||
return self.dbi.delete_user(username)
|
||||
|
||||
def update_user(self, username, password):
|
||||
self.usercache = {}
|
||||
self.mc.delete(username)
|
||||
self.mc.set(username, password)
|
||||
return self.dbi.update_user(username, password)
|
||||
|
||||
def update_worker_diff(self, username, diff):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user