From 72876fc68385861e06fd900707c3a7c28d040a7d Mon Sep 17 00:00:00 2001
From: UbitUmarov
Date: Tue, 16 Aug 2016 23:11:01 +0100
Subject:  drasticly reduce HG inventory caches Expire times, Remove them all
 onClientClose. This to avoid potencial desyncs with inventory service

---
 .../Inventory/HGInventoryBroker.cs                    | 19 ++++++++++---------
 .../ServiceConnectorsOut/Inventory/InventoryCache.cs  | 13 ++++++++++++-
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs
index 863560b..c48186f 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs
@@ -203,21 +203,22 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
 
         void OnClientClosed(UUID clientID, Scene scene)
         {
-            if (m_InventoryURLs.ContainsKey(clientID)) // if it's in cache
+            ScenePresence sp = null;
+            foreach (Scene s in m_Scenes)
             {
-                ScenePresence sp = null;
-                foreach (Scene s in m_Scenes)
+                s.TryGetScenePresence(clientID, out sp);
+                if ((sp != null) && !sp.IsChildAgent && (s != scene))
                 {
-                    s.TryGetScenePresence(clientID, out sp);
-                    if ((sp != null) && !sp.IsChildAgent && (s != scene))
-                    {
-                        m_log.DebugFormat("[INVENTORY CACHE]: OnClientClosed in {0}, but user {1} still in sim. Keeping inventoryURL in cache",
+                    m_log.DebugFormat("[INVENTORY CACHE]: OnClientClosed in {0}, but user {1} still in sim. Keeping inventoryURL in cache",
                             scene.RegionInfo.RegionName, clientID);
                         return;
-                    }
                 }
-                DropInventoryServiceURL(clientID);
             }
+
+            if (m_InventoryURLs.ContainsKey(clientID)) // if it's in cache
+                    DropInventoryServiceURL(clientID);
+
+            m_Cache.RemoveAll(clientID);
         }
 
         /// <summary>
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs
index 3195e6b..f7ef2ea 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs
@@ -38,12 +38,23 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
     /// </summary>
     public class InventoryCache
     {
-        private const double CACHE_EXPIRATION_SECONDS = 3600.0; // 1 hour
+        private const double CACHE_EXPIRATION_SECONDS = 60.0; // 1 minute
 
         private static ExpiringCache<UUID, InventoryFolderBase> m_RootFolders = new ExpiringCache<UUID, InventoryFolderBase>();
         private static ExpiringCache<UUID, Dictionary<FolderType, InventoryFolderBase>> m_FolderTypes = new ExpiringCache<UUID, Dictionary<FolderType, InventoryFolderBase>>();
         private static ExpiringCache<UUID, InventoryCollection> m_Inventories = new ExpiringCache<UUID, InventoryCollection>();
 
+
+        public void RemoveAll(UUID userID)
+        {
+            if(m_RootFolders.Contains(userID))
+                m_RootFolders.Remove(userID);
+            if(m_FolderTypes.Contains(userID))
+                m_FolderTypes.Remove(userID);
+            if(m_Inventories.Contains(userID))
+                m_Inventories.Remove(userID);
+        }
+
         public void Cache(UUID userID, InventoryFolderBase root)
         {
             m_RootFolders.AddOrUpdate(userID, root, CACHE_EXPIRATION_SECONDS);
-- 
cgit v1.1