Commit 416ea907 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

erp5_web: update caching policy behavior. Add possibility to select caching...

erp5_web: update caching policy behavior. Add possibility to select caching policy from WebSite and WebSection

erp5_web: simple yet effective caching policy rules

erp5_web: caching policy fix update names

erp5_web: introduce caching policy category for Web Site and Web Section

erp5_web: fix test related to caching policies

erp5_web: Fix Base_getWebDocumentDrivenModificationDate for empty web sites.

erp5_web: fix Base_getWebDocumentDrivenModificationDate

erp5_web: optimize , fix caching policy

erp5_web: update Base_getWebDocumentDrivenModificationDate portal type list
parent 1c938e16
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Base Category" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_folders_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Copy_or_Move_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Delete_objects_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_count</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_mt_index</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>_tree</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>caching_policy</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>caching_policy</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Base Category</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Caching Policy</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Length" module="BTrees.Length"/>
</pickle>
<pickle> <int>0</int> </pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Category" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_folders_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Copy_or_Move_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Delete_objects_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>caching_policy/no-cache</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>no-cache</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Category</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>No Cache</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Category" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_folders_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Copy_or_Move_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Delete_objects_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>caching_policy/one-day-max-modification-date</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>one-day-max-modification-date</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Category</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>One Day Max Modification Date</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -10,9 +10,11 @@ ...@@ -10,9 +10,11 @@
</portal_type> </portal_type>
<portal_type id="Web Section"> <portal_type id="Web Section">
<item>aggregate</item> <item>aggregate</item>
<item>caching_policy</item>
</portal_type> </portal_type>
<portal_type id="Web Site"> <portal_type id="Web Site">
<item>aggregate</item> <item>aggregate</item>
<item>caching_policy</item>
</portal_type> </portal_type>
<portal_type id="Web Site Module"> <portal_type id="Web Site Module">
<item>business_application</item> <item>business_application</item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from Products.ERP5Type.Cache import CachingMethod\n
\n
def getLatestModificationDate():\n
document = context.getPortalObject().portal_catalog(\n
portal_type=("Web Section", "Web Site",) + context.getPortalDocumentTypeList(),\n
sort_on=((\'modification_date\', \'descending\'),),\n
select_list=(\'modification_date\',),\n
limit=1,\n
)\n
if document:\n
return document[0].modification_date\n
return getattr(context, \'getModificationDate\', context.modified)()\n
\n
getLatestModificationDate = CachingMethod(\n
getLatestModificationDate,\n
id="Base_getWebDocumentDrivenModificationDate",\n
cache_factory="erp5_content_short",\n
)\n
\n
return getLatestModificationDate()\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getWebDocumentDrivenModificationDate</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -101,6 +101,7 @@ ...@@ -101,6 +101,7 @@
<string>my_authorization_forced</string> <string>my_authorization_forced</string>
<string>my_site_map_section_parent</string> <string>my_site_map_section_parent</string>
<string>my_site_map_document_parent</string> <string>my_site_map_document_parent</string>
<string>my_caching_policy</string>
</list> </list>
</value> </value>
</item> </item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_caching_policy</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_category</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Caching Policy</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -114,6 +114,7 @@ ...@@ -114,6 +114,7 @@
<string>my_authorization_forced</string> <string>my_authorization_forced</string>
<string>my_site_map_section_parent</string> <string>my_site_map_section_parent</string>
<string>my_site_map_document_parent</string> <string>my_site_map_document_parent</string>
<string>my_caching_policy</string>
</list> </list>
</value> </value>
</item> </item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_caching_policy</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_category</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Caching Policy</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
caching_policy
publication_section publication_section
similar similar
\ No newline at end of file
portal_alarms/fetch_incoming_web_message_list portal_alarms/fetch_incoming_web_message_list
portal_categories/caching_policy/**
portal_contribution_registry/web_page_by_content portal_contribution_registry/web_page_by_content
portal_contribution_registry/webpage_extension portal_contribution_registry/webpage_extension
portal_contribution_registry/webpage_mimetype portal_contribution_registry/webpage_mimetype
......
...@@ -4,5 +4,7 @@ Web Page | publication_section ...@@ -4,5 +4,7 @@ Web Page | publication_section
Web Page | similar Web Page | similar
Web Page | successor Web Page | successor
Web Section | aggregate Web Section | aggregate
Web Section | caching_policy
Web Site Module | business_application Web Site Module | business_application
Web Site | aggregate Web Site | aggregate
\ No newline at end of file Web Site | caching_policy
\ No newline at end of file
...@@ -434,6 +434,8 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -434,6 +434,8 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional):
document = document_module.newContent(portal_type=document_portal_type, document = document_module.newContent(portal_type=document_portal_type,
reference='NXD-Document-TEXT.Cache') reference='NXD-Document-TEXT.Cache')
document.publish() document.publish()
# Evaluation of last modification date for the site is cached
self.portal.portal_caches.clearCache(cache_factory_list=('erp5_content_short', ))
self.tic() self.tic()
response = self.publish(website_url + '/NXD-Document-TEXT.Cache') response = self.publish(website_url + '/NXD-Document-TEXT.Cache')
last_modified_header = response.getHeader('Last-Modified') last_modified_header = response.getHeader('Last-Modified')
...@@ -450,13 +452,14 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -450,13 +452,14 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional):
reference = 'P-DMS-Presentation.3.Pages' reference = 'P-DMS-Presentation.3.Pages'
document.edit(reference=reference) document.edit(reference=reference)
document.publish() document.publish()
self.portal.portal_caches.clearCache(cache_factory_list=('erp5_content_short', ))
self.tic() self.tic()
# Check we can access to the 3 drawings converted into images. # Check we can access to the 3 drawings converted into images.
# Those images can be accessible through extensible content # Those images can be accessible through extensible content
# url : path-of-document + '/' + 'img' + page-index + '.png' # url : path-of-document + '/' + 'img' + page-index + '.png'
policy_list = self.portal.caching_policy_manager.listPolicies() policy_list = self.portal.caching_policy_manager.listPolicies()
policy = [policy[1] for policy in policy_list\ policy = [policy[1] for policy in policy_list\
if policy[0] == 'unauthenticated'][0] if policy[0] == 'unauthenticated no language'][0]
for i in xrange(3): for i in xrange(3):
path = '/'.join((website_url, path = '/'.join((website_url,
reference, reference,
...@@ -464,10 +467,15 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -464,10 +467,15 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional):
response = self.publish(path) response = self.publish(path)
policy_list = self.portal.caching_policy_manager.listPolicies() policy_list = self.portal.caching_policy_manager.listPolicies()
policy = [policy for policy in policy_list\ policy = [policy for policy in policy_list\
if policy[0] == 'unauthenticated'][0] if policy[0] == 'unauthenticated no language'][0]
self.assertEquals(response.getHeader('Content-Type'), 'image/png') self.assertEquals(response.getHeader('Content-Type'), 'image/png')
self.assertEquals(response.getHeader('Cache-Control'), self.assertEquals(
'max-age=%s, public' % policy[1].getMaxAgeSecs()) response.getHeader('Cache-Control'),
'max-age=%s, stale-while-revalidate=%s, public' % (
policy[1].getMaxAgeSecs(),
policy[1].getStaleWhileRevalidateSecs(),
)
)
def test_07_TestDocumentViewBehaviour(self): def test_07_TestDocumentViewBehaviour(self):
"""All Documents shared the same downloading behaviour """All Documents shared the same downloading behaviour
...@@ -590,6 +598,8 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -590,6 +598,8 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional):
document = document_module.newContent(portal_type=document_portal_type, document = document_module.newContent(portal_type=document_portal_type,
reference='NXD-Document-1-TEXT.Cache') reference='NXD-Document-1-TEXT.Cache')
document.publish() document.publish()
# Evaluation of last modification date for the site is cached
self.portal.portal_caches.clearCache(cache_factory_list=('erp5_content_short', ))
self.tic() self.tic()
response = self.publish(website_url + '/NXD-Document-1-TEXT.Cache') response = self.publish(website_url + '/NXD-Document-1-TEXT.Cache')
last_modified_header = response.getHeader('Last-Modified') last_modified_header = response.getHeader('Last-Modified')
...@@ -606,20 +616,21 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -606,20 +616,21 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional):
reference = 'P-DMS-Presentation-001-.3.Pages' reference = 'P-DMS-Presentation-001-.3.Pages'
document.edit(reference=reference) document.edit(reference=reference)
document.publish() document.publish()
self.portal.portal_caches.clearCache(cache_factory_list=('erp5_content_short', ))
self.tic() self.tic()
# Check we can access to the 3 drawings converted into images. # Check we can access to the 3 drawings converted into images.
# Those images can be accessible through extensible content # Those images can be accessible through extensible content
# url : path-of-document + '/' + 'img' + page-index + '.png' # url : path-of-document + '/' + 'img' + page-index + '.png'
# Update policy to have stale values # Update policy to have stale values
self.portal.caching_policy_manager._updatePolicy( self.portal.caching_policy_manager._updatePolicy(
"unauthenticated", "python: member is None", "unauthenticated no language", "python: member is None",
"python: getattr(object, 'getModificationDate', object.modified)()", "python: getattr(object, 'getModificationDate', object.modified)()",
1200, 30, 600, 0, 0, 0, "Accept-Language, Cookie", "", None, 1200, 30, 600, 0, 0, 0, "Accept-Language, Cookie", "", None,
0, 1, 0, 0, 1, 1, None, None) 0, 1, 0, 0, 1, 1, None, None)
self.tic() self.tic()
policy_list = self.portal.caching_policy_manager.listPolicies() policy_list = self.portal.caching_policy_manager.listPolicies()
policy = [policy[1] for policy in policy_list\ policy = [policy[1] for policy in policy_list\
if policy[0] == 'unauthenticated'][0] if policy[0] == 'unauthenticated no language'][0]
# Check policy has been updated # Check policy has been updated
self.assertEquals(policy.getMaxAgeSecs(), 1200) self.assertEquals(policy.getMaxAgeSecs(), 1200)
self.assertEquals(policy.getStaleWhileRevalidateSecs(), 30) self.assertEquals(policy.getStaleWhileRevalidateSecs(), 30)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment