From 93e2a1fd8c0c5c7e0249c5ba97f861a442326124 Mon Sep 17 00:00:00 2001 From: Simon G Date: Tue, 10 Nov 2020 15:26:20 +0100 Subject: [PATCH] #25: adapt cache --- GBase/DataHandling/Cache/XmlDataHandlerCache.cs | 8 ++++++-- GBase/DataHandling/XmlDataHandler.cs | 2 +- GBase/Interfaces/DataHandling/Cache/IDataHandlerCache.cs | 6 +++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/GBase/DataHandling/Cache/XmlDataHandlerCache.cs b/GBase/DataHandling/Cache/XmlDataHandlerCache.cs index 43d7883..e6db2a2 100644 --- a/GBase/DataHandling/Cache/XmlDataHandlerCache.cs +++ b/GBase/DataHandling/Cache/XmlDataHandlerCache.cs @@ -4,7 +4,9 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Threading; using System.Threading.Tasks; using GBase.DataHandling.Cache.Factories; using GBase.Interfaces.DataHandling.Cache; @@ -103,9 +105,11 @@ namespace GBase.DataHandling.Cache /// /// The that implements the property /// The of the property + /// /// The name of the property + /// /// An with all the values for the property - public async Task> TryGetValues(string propertyName) + public async Task> TryGetValues(FileStream file, string propertyName, CancellationToken cancellationToken) { IXmlDataHandlerCacheEntry entry = _cache.FirstOrDefault(e => e.Type == typeof(T)); IDataHandlerCachePropertyEntry property = entry?.Properties.FirstOrDefault(p => p.PropertyName.Equals(propertyName)); @@ -114,7 +118,7 @@ namespace GBase.DataHandling.Cache if (!property.IsInitialized) //initialize property by reading the values from the xml { - List values = (await _xmlDataReader.Read(propertyName))?.ToList(); + List values = (await _xmlDataReader.Read(file, propertyName, cancellationToken))?.ToList(); if (values != null) { foreach (TProperty value in values.Where(value => !property.Values.Any(v => v.Equals(value)))) diff --git a/GBase/DataHandling/XmlDataHandler.cs b/GBase/DataHandling/XmlDataHandler.cs index b61a2dd..64c2901 100644 --- a/GBase/DataHandling/XmlDataHandler.cs +++ b/GBase/DataHandling/XmlDataHandler.cs @@ -184,7 +184,7 @@ namespace GBase.DataHandling /// An with all the values for the property public async Task> GetValues(FileStream file, string propertyName, CancellationToken cancellationToken) { - IEnumerable cachedValues = await _cache.TryGetValues(propertyName); + IEnumerable cachedValues = await _cache.TryGetValues(file, propertyName, cancellationToken); if (cachedValues != null) return cachedValues; diff --git a/GBase/Interfaces/DataHandling/Cache/IDataHandlerCache.cs b/GBase/Interfaces/DataHandling/Cache/IDataHandlerCache.cs index e02a452..9bcba60 100644 --- a/GBase/Interfaces/DataHandling/Cache/IDataHandlerCache.cs +++ b/GBase/Interfaces/DataHandling/Cache/IDataHandlerCache.cs @@ -4,6 +4,8 @@ using System; using System.Collections.Generic; +using System.IO; +using System.Threading; using System.Threading.Tasks; namespace GBase.Interfaces.DataHandling.Cache @@ -39,8 +41,10 @@ namespace GBase.Interfaces.DataHandling.Cache /// /// The that implements the property /// The of the property + /// /// The name of the property + /// /// An with all the values for the property - Task> TryGetValues(string propertyName); + Task> TryGetValues(FileStream file, string propertyName, CancellationToken cancellationToken); } } \ No newline at end of file