diff --git a/src/ImageProcessor.Web/Caching/CachedImage.cs b/src/ImageProcessor.Web/Caching/CachedImage.cs
index 41241cb1b..2819bf2d3 100644
--- a/src/ImageProcessor.Web/Caching/CachedImage.cs
+++ b/src/ImageProcessor.Web/Caching/CachedImage.cs
@@ -17,35 +17,38 @@ namespace ImageProcessor.Web.Caching
///
/// Describes a cached image
///
- internal sealed class CachedImage
+ public sealed class CachedImage
{
- //[PrimaryKey, AutoIncrement]
- //public int Id { get; set; }
+ ///
+ /// Gets or sets the id identifying the cached image.
+ ///
+ [PrimaryKey, AutoIncrement]
+ public int Id { get; set; }
///
/// Gets or sets the key identifying the cached image.
///
- [PrimaryKey]
- internal string Key { get; set; }
+ [Unique]
+ public string Key { get; set; }
///
/// Gets or sets the value of the cached image.
///
- internal string Path { get; set; }
+ public string Path { get; set; }
///
/// Gets or sets the maximum age of the cached image in days.
///
- internal int MaxAge { get; set; }
+ public int MaxAge { get; set; }
///
/// Gets or sets the last write time of the cached image.
///
- internal DateTime LastWriteTimeUtc { get; set; }
+ public DateTime LastWriteTimeUtc { get; set; }
///
/// Gets or sets when the cached image should expire from the cache.
///
- internal DateTime ExpiresUtc { get; set; }
+ public DateTime ExpiresUtc { get; set; }
}
}
diff --git a/src/ImageProcessor.Web/Caching/PersistantDictionary.cs b/src/ImageProcessor.Web/Caching/PersistantDictionary.cs
index 644d74364..5d1ce3616 100644
--- a/src/ImageProcessor.Web/Caching/PersistantDictionary.cs
+++ b/src/ImageProcessor.Web/Caching/PersistantDictionary.cs
@@ -76,10 +76,14 @@ namespace ImageProcessor.Web.Caching
// Remove the CachedImage.
CachedImage value = this[key];
- this.Remove(key);
- await this.SaveCacheAsync(key, value, true);
- return true;
+ if (await this.SaveCacheAsync(key, value, true) > 0)
+ {
+ this.Remove(key);
+ return true;
+ }
+
+ return false;
}
///
@@ -97,7 +101,7 @@ namespace ImageProcessor.Web.Caching
public async Task AddAsync(string key, CachedImage cachedImage)
{
// Add the CachedImage.
- if (await this.SaveCacheAsync(key, cachedImage, false))
+ if (await this.SaveCacheAsync(key, cachedImage, false) > 0)
{
this.Add(key, cachedImage);
}
@@ -121,7 +125,7 @@ namespace ImageProcessor.Web.Caching
///
/// true, if the dictionary is saved to the file-system; otherwise, false.
///
- private async Task SaveCacheAsync(string key, CachedImage cachedImage, bool remove)
+ private async Task SaveCacheAsync(string key, CachedImage cachedImage, bool remove)
{
try
{
@@ -134,7 +138,7 @@ namespace ImageProcessor.Web.Caching
}
catch
{
- return false;
+ return 0;
}
}
diff --git a/src/ImageProcessor.Web/Caching/SQLContext.cs b/src/ImageProcessor.Web/Caching/SQLContext.cs
index 1f5be5475..dd939d464 100644
--- a/src/ImageProcessor.Web/Caching/SQLContext.cs
+++ b/src/ImageProcessor.Web/Caching/SQLContext.cs
@@ -119,7 +119,7 @@ namespace ImageProcessor.Web.Caching
///
/// The true if the addition of the cached image is added; otherwise, false.
///
- internal static async Task AddImageAsync(CachedImage image)
+ internal static async Task AddImageAsync(CachedImage image)
{
// Create Action delegate for AddImage.
return await TaskHelpers.Run(() => AddImage(image));
@@ -134,7 +134,7 @@ namespace ImageProcessor.Web.Caching
///
/// The true if the addition of the cached image is removed; otherwise, false.
///
- internal static async Task RemoveImageAsync(string key)
+ internal static async Task RemoveImageAsync(string key)
{
// Create Action delegate for RemoveImage.
return await TaskHelpers.Run(() => RemoveImage(key));
@@ -152,24 +152,21 @@ namespace ImageProcessor.Web.Caching
///
/// The true if the addition of the cached image is added; otherwise, false.
///
- private static bool AddImage(CachedImage image)
+ private static int AddImage(CachedImage image)
{
try
{
+ int id = 0;
SQLiteConnection connection = new SQLiteConnection(ConnectionString);
- connection.RunInTransaction(() =>
- {
- // Database calls inside the transaction
- connection.Insert(image);
- connection.Dispose();
- });
+ id = connection.Insert(image);
+ connection.Dispose();
- return true;
+ return id;
}
catch
{
- return false;
+ return 0;
}
}
@@ -182,24 +179,21 @@ namespace ImageProcessor.Web.Caching
///
/// The true if the addition of the cached image is removed; otherwise, false.
///
- private static bool RemoveImage(string key)
+ private static int RemoveImage(string key)
{
try
{
+ int id = 0;
SQLiteConnection connection = new SQLiteConnection(ConnectionString);
- connection.RunInTransaction(() =>
- {
- // Database calls inside the transaction
- connection.Delete(key);
- connection.Dispose();
- });
+ id = connection.Delete(key);
+ connection.Dispose();
- return true;
+ return id;
}
catch
{
- return false;
+ return 0;
}
}
#endregion
diff --git a/src/ImageProcessor.Web/ImageProcessor.Web.csproj b/src/ImageProcessor.Web/ImageProcessor.Web.csproj
index 60e5b6ed6..fcfdaf4fe 100644
--- a/src/ImageProcessor.Web/ImageProcessor.Web.csproj
+++ b/src/ImageProcessor.Web/ImageProcessor.Web.csproj
@@ -26,14 +26,14 @@
pdbonly
true
bin\Release\
- TRACE
+ TRACE;USE_CSHARP_SQLITE
prompt
4
true
bin\All\
- DEBUG;TRACE
+ TRACE;DEBUG
full
AnyCPU
prompt