Hi,
Can anybody explain what's the use of the decorator @tools.ormcache .
For example, the line '@tools.ormcache('frozenset(self.env.user.groups_id.ids)', 'debug')' have what effect in a function ?
Thanks.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
Hi,
@tools.ormcache is a decorator which helps to store dataset in memory cache. This is the methodology to manage cache for your functions.
For example there is method which calls every time when you reload any page at Odoo then every time it execute definition of that function. Due to this page takes to much time to load.
So in order to avid this issue Odoo introduces this decorator which stores the method response in memory cache. Then whenever someone trigger this method then instead of executing definition of this method it takes the response directly from cache.
Example:
@api.model
@tools.ormcache('self.env.cr.dbname')
def get_setting(self):
return int(
self.env['ir.config_parameter'].sudo().get_param('demo.setting',0)
)
Now in case you change setting then you can clear cache in write function using "clear_cache()",
def write(self, vals):
res = super(IrConfigParameter, self).write(vals)
self.get_setting.clear_cache(self.filtered(lambda r: r.key == 'demo.setting))
return res
Feel free to ask in case of any confusion,
Thanks,
Ashish Singh (Team Lead)
Webkul Software Private Limited
Hi Ashish,
Thanks for this detailed explanation.
Can i ask a doubt, in the line "@tools.ormcache('frozenset(self.env.user.groups_id.ids)", how does it related to the field self.env.user.groups_id ?
Hi, Frodo
Basically "self.env.user.groups_id" helps to give the list of user groups currently user have. If for that syntax cache will be stored for these groups only.
Hi,
You can see some working examples of ormcashe in the below link
https://programtalk.com/python-examples/openerp.tools.ormcache/
By Python Brains
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
2
thg 10 20
|
3336 | ||
|
1
thg 10 22
|
4279 | ||
|
0
thg 6 21
|
5034 | ||
|
1
thg 9 20
|
4844 | ||
|
0
thg 7 20
|
4791 |
See pages 23,24 & 25: https://docs.huihoo.com/odoo/training/reference-material/advanced-features-of-the-api.pdf