diff --git a/GUIs.Common/DocumentResultList/Cache.vb b/GUIs.Common/DocumentResultList/Cache.vb index 1285cd5d..a10f5700 100644 --- a/GUIs.Common/DocumentResultList/Cache.vb +++ b/GUIs.Common/DocumentResultList/Cache.vb @@ -1,8 +1,11 @@ -Imports DigitalData.Modules.EDMI.API.Client +Imports DigitalData.Modules.Base +Imports DigitalData.Modules.EDMI.API.Client +Imports DigitalData.Modules.Logging Namespace DocumentResultList Public Class Cache + Inherits BaseClass Implements ICollection(Of Document) Private Const _DefaultCapacity As Long = 1000 @@ -17,16 +20,20 @@ Namespace DocumentResultList Private ReadOnly Index As New Dictionary(Of String, LinkedListNode(Of Document)) Private ReadOnly Lock As New Object - Public Sub New() - Me.New(_DefaultCapacity) + Public Sub New(pLogConfig As LogConfig) + Me.New(pLogConfig, _DefaultCapacity) End Sub - Public Sub New(capacity As Long) - If capacity < 0 Then + Public Sub New(pLogConfig As LogConfig, pCapacity As Long) + MyBase.New(pLogConfig) + + If pCapacity < 0 Then Throw New InvalidOperationException("DocumentResultCache capacity must be positive.") End If - Me.Capacity = capacity + Logger.Debug("Initializing DocumentResultCache with capacity of [{0}] bytes.", pCapacity) + + Me.Capacity = pCapacity End Sub Public Event DiscardingOldestItem As EventHandler @@ -40,6 +47,8 @@ Namespace DocumentResultList End Property Public Sub Add(pItem As Document) Implements ICollection(Of Document).Add + Logger.Debug("Adding document [{0}].", pItem.Id) + SyncLock Lock If Index.ContainsKey(pItem.Id) Then List.Remove(Index(pItem.Id)) @@ -64,6 +73,10 @@ Namespace DocumentResultList Return Index.ContainsKey(pItem.Id) End Function + Public Function Contains(pDocumentId As Long) As Boolean + Return Index.ContainsKey(pDocumentId) + End Function + Public Sub CopyTo(pArray As Document(), pIndex As Integer) Implements ICollection(Of Document).CopyTo SyncLock Lock For Each item As Document In Me @@ -86,6 +99,8 @@ Namespace DocumentResultList End Property Public Function Remove(pItem As Document) As Boolean Implements ICollection(Of Document).Remove + Logger.Debug("Removing document [{0}].", pItem.Id) + SyncLock Lock If Index.ContainsKey(pItem.Id) Then diff --git a/GUIs.Common/DocumentResultList/Loader.vb b/GUIs.Common/DocumentResultList/Loader.vb index 40b87751..2cb6815b 100644 --- a/GUIs.Common/DocumentResultList/Loader.vb +++ b/GUIs.Common/DocumentResultList/Loader.vb @@ -6,6 +6,7 @@ Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Base.IDB Imports DigitalData.Modules.ZooFlow.Constants Imports DigitalData.Modules.Base +Imports DigitalData.Modules.ZooFlow Namespace DocumentResultList @@ -14,29 +15,50 @@ Namespace DocumentResultList Private ReadOnly Client As Client Private ReadOnly Mode As OperationMode - Private ReadOnly User As DigitalData.Modules.ZooFlow.State.UserState + Private ReadOnly User As State.UserState - Public Sub New(pLogConfig As LogConfig, pMode As OperationMode, pClient As Client, pUser As DigitalData.Modules.ZooFlow.State.UserState) + Private ReadOnly Cache As Cache + + Public Sub New(pLogConfig As LogConfig, pMode As OperationMode, pClient As Client, pUser As State.UserState) MyBase.New(pLogConfig) Client = pClient Mode = pMode User = pUser + + ' Set up cache with capacity of 100 MB + Cache = New Cache(104_900_000) End Sub - Public Function Load(pObjectId As Long, pFullPath As String) As Document + Public Sub Invalidate(pDocument As Document) + Cache.Remove(pDocument) + End Sub + + Public Function Load(pObjectId As Long, pFullPath As String, Optional pForce As Boolean = False) As Document + Dim oDocument As Document = Nothing + + If Cache.Contains(pObjectId) And pForce = False Then + Return Cache.Where(Function(doc) doc.Id = pObjectId).Single() + End If + Select Case Mode Case OperationMode.NoAppServer - Return Load_FromWindream(pObjectId, pFullPath) + oDocument = Load_FromWindream(pObjectId, pFullPath) Case OperationMode.WithAppServer - Return Load_FromIDB(pObjectId) + oDocument = Load_FromIDB(pObjectId) Case OperationMode.ZooFlow - Return Load_FromZooflow(pObjectId) + oDocument = Load_FromZooflow(pObjectId) Case Else - Return Nothing + oDocument = Nothing End Select + + If oDocument IsNot Nothing Then + Cache.Add(oDocument) + End If + + Return oDocument End Function Private Function Load_FromWindream(pObjectId As Long, pFullPath As String) As Document diff --git a/GUIs.Common/frmDocumentResultList.vb b/GUIs.Common/frmDocumentResultList.vb index a54c3d05..a8d7f694 100644 --- a/GUIs.Common/frmDocumentResultList.vb +++ b/GUIs.Common/frmDocumentResultList.vb @@ -50,7 +50,6 @@ Public Class frmDocumentResultList Private ReadOnly Filesystem As Modules.Filesystem.File Private ReadOnly GridBuilder As GridBuilder Private ReadOnly FileEx As Modules.Windows.File - Private ReadOnly Cache As New DocumentResultList.Cache(50000000) Private ReadOnly Helpers As DocumentResultList.Helpers Private ReadOnly Params As DocumentResultList.Params @@ -322,6 +321,7 @@ Public Class frmDocumentResultList .Language = Environment.User.Language, .Username = Environment.User.UserName }) + Documentloader.Invalidate(pFile.Document) If IsNothing(oObjectId) Then MsgBox($"Beim Speichern der Datei '{oDisplayName}' Fehler ist ein Fehler aufgetreten!", MsgBoxStyle.Critical, Text)