How it works...

The ORM cache keeps the cache in dictionary format (the cache lookup). The keys of this cache will be generated based on the signature of the decorated method and the values will be the result. Put simply, when you call the method with the x, y parameters and the result of the method is x+y, the cache lookup will be {(x, y): x+y}. This means that the next time you call this method with the same parameters, the result will be served directly from this cache. This saves computation time and makes the response faster.

The ORM cache is an in-memory cache, so it is stored in the RAM and occupies memory. Do not use the ormcache to serve large data, such as images or files.

Methods using this decorator should never return a recordset. If you do this, they will generate a psycopg2.OperationalError because the underlying cursor of the recordset is closed.

You should use the ORM cache on pure functions. A pure function is a method that always returns the same result for the same arguments. The output of these methods only depends on the arguments and so they return the same result. If this is not the case, you need to manually clear the cache when you perform operations that make the cache's state invalid. To clear the cache, call the clear_caches() method:

self.env[model_name].clear_caches()
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset