[IMP] tools.cache: added missing clean_caches_for_db replacement.

bzr revid: vmt@openerp.com-20110825124711-y2uckmvcoa0arz4h
This commit is contained in:
Vo Minh Thu 2011-08-25 14:47:11 +02:00
parent 86965e3884
commit 6fdadb04f5
4 changed files with 39 additions and 2 deletions

View File

@ -82,6 +82,15 @@ class Registry(object):
return res
def clear_caches
""" Clear the caches
This clears the caches associated to methods decorated with
``tools.ormcache`` or ``tools.ormcache_multi`` for all the models.
"""
for model in self.models.itervalues():
model.clear_caches()
class RegistryManager(object):
""" Model registries manager.
@ -155,4 +164,19 @@ class RegistryManager(object):
del cls.registries[db_name]
@classmethod
def clear_caches(db_name)
""" Clear the caches
This clears the caches associated to methods decorated with
``tools.ormcache`` or ``tools.ormcache_multi`` for all the models
of the given database name.
This method is given to spare you a ``RegistryManager.get(db_name)``
that would loads the given database if it was not already loaded.
"""
if db_name in cls.registries:
del cls.registries[db_name].clear_caches()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -2251,6 +2251,18 @@ class orm_template(object):
values = defaults
return values
def clear_caches(self):
""" Clear the caches
This clears the caches associated to methods decorated with
``tools.ormcache`` or ``tools.ormcache_multi``.
"""
try:
getattr(self, '_ormcache')
self._ormcache = {}
except AttributeError:
pass
class orm_memory(orm_template):
_protected = ['read', 'write', 'create', 'default_get', 'perm_read', 'unlink', 'fields_get', 'fields_view_get', 'search', 'name_get', 'distinct_field_get', 'name_search', 'copy', 'import_data', 'search_count', 'exists']

View File

@ -155,6 +155,7 @@ class db(netsvc.ExportService):
def exp_drop(self, db_name):
sql_db.close_db(db_name)
openerp.modules.registry.RegistryManager.clear_caches(db_name)
openerp.netsvc.Agent.cancel(db_name)
logger = netsvc.Logger()
@ -258,7 +259,8 @@ class db(netsvc.ExportService):
def exp_rename(self, old_name, new_name):
sql_db.close_db(old_name)
openerp.netsvc.Agent.cancel(db_name)
openerp.modules.registry.RegistryManager.clear_caches(old_name)
openerp.netsvc.Agent.cancel(old_name)
logger = netsvc.Logger()
db = sql_db.db_connect('template1')

View File

@ -500,7 +500,6 @@ def db_connect(db_name):
def close_db(db_name):
""" You might want to call openerp.netsvc.Agent.cancel(db_name) along this function."""
_Pool.close_all(dsn(db_name))
tools.cache.clean_caches_for_db(db_name)
ct = currentThread()
if hasattr(ct, 'dbname'):
delattr(ct, 'dbname')