Common/DocumentResultList: Add caching
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user