mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 22:46:58 +00:00
Version 4.12.2 Improved TileImageLoader.Cache
This commit is contained in:
parent
a25cc91c2f
commit
85287118a5
8 changed files with 139 additions and 116 deletions
|
|
@ -53,6 +53,12 @@
|
|||
</None>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\MapControl\WPF\MapControl.WPF.csproj">
|
||||
<Project>{a204a102-c745-4d65-aec8-7b96faedef2d}</Project>
|
||||
<Name>MapControl.WPF</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
|
|
|||
|
|
@ -149,11 +149,15 @@ namespace MapControl.Caching
|
|||
{
|
||||
try
|
||||
{
|
||||
var record = fileDb.GetRecordByKey(key, new string[] { valueField }, false);
|
||||
var record = fileDb.GetRecordByKey(key, new string[] { valueField, expiresField }, false);
|
||||
|
||||
if (record != null)
|
||||
{
|
||||
return record[0];
|
||||
return new ImageCacheItem
|
||||
{
|
||||
Buffer = (byte[])record[0],
|
||||
Expiration = (DateTime)record[1]
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -184,38 +188,21 @@ namespace MapControl.Caching
|
|||
throw new ArgumentNullException("The parameter key must not be null.");
|
||||
}
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
throw new ArgumentNullException("The parameter value must not be null.");
|
||||
}
|
||||
|
||||
if (policy == null)
|
||||
{
|
||||
throw new ArgumentNullException("The parameter policy must not be null.");
|
||||
}
|
||||
|
||||
if (regionName != null)
|
||||
{
|
||||
throw new NotSupportedException("The parameter regionName must be null.");
|
||||
}
|
||||
|
||||
if (fileDb.IsOpen)
|
||||
var imageCacheItem = value as ImageCacheItem;
|
||||
|
||||
if (imageCacheItem == null || imageCacheItem.Buffer == null || imageCacheItem.Buffer.Length == 0)
|
||||
{
|
||||
var expiration = DateTime.MaxValue;
|
||||
throw new NotSupportedException("The parameter value must be an ImageCacheItem with a non-empty Buffer.");
|
||||
}
|
||||
|
||||
if (policy.AbsoluteExpiration != InfiniteAbsoluteExpiration)
|
||||
{
|
||||
expiration = policy.AbsoluteExpiration.DateTime;
|
||||
}
|
||||
else if (policy.SlidingExpiration != NoSlidingExpiration)
|
||||
{
|
||||
expiration = DateTime.UtcNow + policy.SlidingExpiration;
|
||||
}
|
||||
|
||||
if (!AddOrUpdateRecord(key, value, expiration) && RepairDatabase())
|
||||
{
|
||||
AddOrUpdateRecord(key, value, expiration);
|
||||
}
|
||||
if (fileDb.IsOpen && !AddOrUpdateRecord(key, imageCacheItem) && RepairDatabase())
|
||||
{
|
||||
AddOrUpdateRecord(key, imageCacheItem);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -354,11 +341,11 @@ namespace MapControl.Caching
|
|||
return false;
|
||||
}
|
||||
|
||||
private bool AddOrUpdateRecord(string key, object value, DateTime expiration)
|
||||
private bool AddOrUpdateRecord(string key, ImageCacheItem imageCacheItem)
|
||||
{
|
||||
var fieldValues = new FieldValues(3);
|
||||
fieldValues.Add(valueField, value);
|
||||
fieldValues.Add(expiresField, expiration);
|
||||
fieldValues.Add(valueField, imageCacheItem.Buffer);
|
||||
fieldValues.Add(expiresField, imageCacheItem.Expiration);
|
||||
|
||||
bool recordExists;
|
||||
|
||||
|
|
@ -398,7 +385,7 @@ namespace MapControl.Caching
|
|||
}
|
||||
}
|
||||
|
||||
//Debug.WriteLine("FileDbCache: Writing \"{0}\", Expires {1}", key, expiration.ToLocalTime());
|
||||
//Debug.WriteLine("FileDbCache: Writing \"{0}\", Expires {1}", key, imageCacheItem.Expiration.ToLocalTime());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue