summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephane Wirtel <stephane@tinyerp.com>2008-12-24 01:36:56 +0100
committerStephane Wirtel <stephane@tinyerp.com>2008-12-24 01:36:56 +0100
commitd2197ffadd4fd72c23a7e701ec9dba47dddb6cb7 (patch)
treea4848b42158281239e0d2ea0c7b96078a3372f34
parentd9be84059db737e015f0154e38a408e8a4c6e28c (diff)
parentca93318a771c1032d072702d4d0cea8fb9603b60 (diff)
[MERGE]
bzr revid: stephane@tinyerp.com-20081224003656-kwftdnreax7m7hbg
-rw-r--r--bin/pooler.py7
-rw-r--r--bin/service/web_services.py4
-rw-r--r--bin/sql_db.py4
-rw-r--r--bin/tools/config.py5
-rw-r--r--bin/tools/misc.py26
5 files changed, 36 insertions, 10 deletions
diff --git a/bin/pooler.py b/bin/pooler.py
index 250ee4f22e5..bf04f30353c 100644
--- a/bin/pooler.py
+++ b/bin/pooler.py
@@ -50,9 +50,10 @@ def get_db_and_pool(db_name, force_demo=False, status=None, update_module=False)
return db, pool
-def restart_pool(db_name, force_demo=False, update_module=False):
- del pool_dic[db_name]
- return get_db_and_pool(db_name, force_demo, update_module=update_module)
+def restart_pool(db_name, force_demo=False, status=None, update_module=False):
+ if db_name in pool_dic:
+ del pool_dic[db_name]
+ return get_db_and_pool(db_name, force_demo, status, update_module=update_module)
def get_db_only(db_name):
diff --git a/bin/service/web_services.py b/bin/service/web_services.py
index 18947afff41..eef02528337 100644
--- a/bin/service/web_services.py
+++ b/bin/service/web_services.py
@@ -82,8 +82,8 @@ class db(netsvc.Service):
cr.commit()
cr.close()
cr = None
- pool = pooler.get_pool(db_name, demo, serv.actions[id],
- update_module=True)
+ pool = pooler.restart_pool(db_name, demo, serv.actions[id],
+ update_module=True)[1]
cr = sql_db.db_connect(db_name).cursor()
diff --git a/bin/sql_db.py b/bin/sql_db.py
index ec8ca3bf176..041f855b32b 100644
--- a/bin/sql_db.py
+++ b/bin/sql_db.py
@@ -227,7 +227,9 @@ def db_connect(db_name, serialize=0):
return PoolManager.get(db_name)
def close_db(db_name):
- return PoolManager.close(db_name)
+ PoolManager.close(db_name)
+ tools.cache.clean_cache_for_db(db_name)
+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/bin/tools/config.py b/bin/tools/config.py
index 7b8ab1df84b..9d3d552a749 100644
--- a/bin/tools/config.py
+++ b/bin/tools/config.py
@@ -76,6 +76,7 @@ class configmanager(object):
'syslog' : False,
'log_level': logging.INFO,
'assert_exit_level': logging.WARNING, # level above which a failed assert will be raise
+ 'cache_timeout': 100000,
}
hasSSL = check_ssl()
@@ -100,6 +101,8 @@ class configmanager(object):
parser.add_option("-i", "--init", dest="init", help="init a module (use \"all\" for all modules)")
parser.add_option("--without-demo", dest="without_demo", help="load demo data for a module (use \"all\" for all modules)", default=False)
parser.add_option("-u", "--update", dest="update", help="update a module (use \"all\" for all modules)")
+ parser.add_option("--cache-timeout", dest="cache_timeout", help="set the timeout for the cache system", default=100000, type="int")
+
# stops the server from launching after initialization
parser.add_option("--stop-after-init", action="store_true", dest="stop_after_init", default=False, help="stop the server after it initializes")
parser.add_option('--debug', dest='debug_mode', action='store_true', default=False, help='enable debug mode')
@@ -186,7 +189,7 @@ class configmanager(object):
self.options['pidfile'] = False
keys = ['interface', 'port', 'db_name', 'db_user', 'db_password', 'db_host',
- 'db_port', 'logfile', 'pidfile', 'smtp_port',
+ 'db_port', 'logfile', 'pidfile', 'smtp_port', 'cache_timeout',
'email_from', 'smtp_server', 'smtp_user', 'smtp_password', 'price_accuracy',
'netinterface', 'netport', 'db_maxconn', 'import_partial', 'addons_path']
diff --git a/bin/tools/misc.py b/bin/tools/misc.py
index 993f4eb03f8..6241365f8d0 100644
--- a/bin/tools/misc.py
+++ b/bin/tools/misc.py
@@ -536,14 +536,34 @@ class cache(object):
Use it as a decorator of the function you plan to cache
Timeout: 0 = no timeout, otherwise in seconds
"""
-
- def __init__(self, timeout=10000, skiparg=2, multi=None):
+
+ __caches = []
+
+ def __init__(self, timeout=None, skiparg=2, multi=None):
assert skiparg >= 2 # at least self and cr
- self.timeout = timeout
+ if timeout is None:
+ self.timeout = config['cache_timeout']
+ else:
+ self.timeout = timeout
self.skiparg = skiparg
self.multi = multi
self.lasttime = time.time()
self.cache = {}
+
+ cache.__caches.append(self)
+
+ @classmethod
+ def clean_cache_for_db(cls, dbname):
+ def get_dbname_from_key(key):
+ for e in key:
+ if e[0] == 'dbname':
+ return e[1]
+ return None
+
+ for cache in cls.__caches:
+ keys_to_del = [key for key in cache.cache if get_dbname_from_key(key) == dbname]
+ for key in keys_to_del:
+ del cache.cache[key]
def __call__(self, fn):
arg_names = inspect.getargspec(fn)[0][self.skiparg:]