From 6df1740425961e01c0ee261008f7b39c865a93f5 Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Thu, 14 Oct 2010 12:50:23 +0000
Subject: [PATCH] Use a persistent sequence number to invalidate catalog cache.

Allows consistent invalidations in a cluster.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39142 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ZSQLCatalog/SQLCatalog.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/product/ZSQLCatalog/SQLCatalog.py b/product/ZSQLCatalog/SQLCatalog.py
index 5920a1e653..392e5feec9 100644
--- a/product/ZSQLCatalog/SQLCatalog.py
+++ b/product/ZSQLCatalog/SQLCatalog.py
@@ -122,6 +122,7 @@ class transactional_cache_decorator:
     def wrapper(wrapped_self):
       transactional_cache = getTransactionalVariable()
       cache_id = str((self.cache_id,
+        wrapped_self.getCacheSequenceNumber(),
         getInstanceID(wrapped_self),
       ))
       try:
@@ -596,6 +597,8 @@ class Catalog(Folder,
   manage_catalogFind = DTMLFile('dtml/catalogFind',globals())
   manage_catalogAdvanced = DTMLFile('dtml/catalogAdvanced', globals())
 
+  _cache_sequence_number = 0
+
   def __init__(self, id, title='', container=None):
     if container is not None:
       self=self.__of__(container)
@@ -606,6 +609,12 @@ class Catalog(Folder,
     self.indexes = {}   # empty mapping
     self.filter_dict = PersistentMapping()
 
+  def getCacheSequenceNumber(self):
+    return self._cache_sequence_number
+
+  def _clearCaches(self):
+    self._cache_sequence_number += 1
+
   def getSQLCatalogRoleKeysList(self):
     """
     Return the list of role keys.
@@ -840,6 +849,7 @@ class Catalog(Folder,
       self.insertMaxUid()
 
     self._clearSecurityCache()
+    self._clearCaches()
 
   def insertMaxUid(self):
     """
-- 
2.30.9