Class: Ooor::ModelRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/ooor/model_registry.rb

Overview

Enables to cache expensive model metadata and reuse these metadata according to connection parameters. Indeed, these metadata are expensive before they require a fields_get request to OpenERP so in a web application with several worker processes, it’s a good idea to cache them and share them using a data store like Memcache

Instance Method Summary collapse

Instance Method Details

#cache_key(config, model_name) ⇒ Object



9
10
11
12
# File 'lib/ooor/model_registry.rb', line 9

def cache_key(config, model_name)
  h = {url: config[:url], database: config[:database], username: config[:username], scope_prefix: config[:scope_prefix]}
  (h.map{|k, v| v} + [model_name]).join('-')
end

#get_template(config, model_name) ⇒ Object



14
15
16
# File 'lib/ooor/model_registry.rb', line 14

def get_template(config, model_name)
  Ooor.cache.read(cache_key(config, model_name))
end

#set_template(config, model) ⇒ Object



18
19
20
21
# File 'lib/ooor/model_registry.rb', line 18

def set_template(config, model)
  key = cache_key(config, model.openerp_model)
  Ooor.cache.write(key, model)
end