Files
odoo_source/addons/website/tests/test_http_endpoint.py
T
Xavier-Do 595aa24843 [IMP] registry: multiple ormcache
One of the main issue with ormcache is that the invalidation clears
everything, meaning that some value, slow to compute but with a long
lifetime, can be removed from the cache because an easy to invalidate
value is cleared, like after writting or creating a product has an
example.

Most example in the code will try to invalidate the cache of the models
doing something like `env['ir.qweb'].clear_caches()` but it is
finally equivalent to `env.registry.clear_cache()`, and cross worker.

The idea is to have multiple cache, maybe with specific sizes for a
specific purpose.

Having one per model is maybe a bad idea because it will be difficult
to size the LRU correcly, and it is too dynamic. Checking invalidation
may be expensive.

The proposed solution is closed allow a limited number of named caches,
using onse sequence per cache. This is actually close to the
cache_longterm.

We want to discourage using a specific cache for one use case in
the buisness code. Adding a cache shouldn't be something easy, doable
in stable.

Note that we could also change the invalisation mecanism using an
insert only table. We an check the sequence of this table, but also
fetch all invalidation messages.
Another possible improvement, especially if we have more than x cache is
to have a global sequence, checking signaling would mean to check the
main sequence, and only the other ones if the main one changed.

Note that this poc is inspired from the long term cache but not all
use case where applie yet.

Part-of: odoo/odoo#119813
2023-07-18 11:42:26 +02:00

40 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import HttpCase
import werkzeug
class TestHttpEndPoint(HttpCase):
def test_can_clear_routing_map_during_render(self):
"""
The routing map might be cleared while rendering a qweb view.
For example, if an asset bundle is regenerated the old one is unlinked,
which causes a cache clearing.
This test ensures that the rendering still works, even in this case.
"""
homepage_view = self.env['ir.ui.view'].search([
('website_id', '=', self.env.ref('website.default_website').id),
('key', '=', 'website.homepage'),
])
self.env['ir.ui.view'].create({
'name': 'Add cache clear to Home',
'type': 'qweb',
'mode': 'extension',
'inherit_id': homepage_view.id,
'arch_db': """
<t t-call="website.layout" position="before">
<t t-esc="website.env.registry.clear_cache('routing')"/>
</t>
""",
})
r = self.url_open('/')
r.raise_for_status()
def test_redirect_double_slash(self):
res = self.url_open('/test_http//greeting', allow_redirects=False)
self.assertIn(res.status_code, (301, 308))
self.assertEqual(werkzeug.urls.url_parse(res.headers.get('Location', '')).path, '/test_http/greeting')