The in-memory cache – ormcache
The Odoo framework provides the ormcache
decorator to manage the in-memory cache. In this recipe, we will explore how you can manage the cache for your functions.
How to do it...
The classes of this ORM cache are available at /odoo/tools/cache.py
. In order to use these in any file, you will need to import them as follows:
from odoo import tools
After importing the classes, you can use the ORM cache decorators. Odoo provides different types of in-memory cache decorators. We’ll take a look at each of these in the following subsections.
ormcache
This one is the simplest and most used cache decorator. You need to pass the parameter name upon which the method’s output depends. The following is an example method with the ormcache
decorator:
@tools.ormcache('mode') def fetch_mode_data(self, mode): # some calculations return result
When you call this method for...