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.
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:
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']
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()
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')
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')