Browse Source

Whoop! It's alive :)

Former-commit-id: 129e3abe7772d08ba133de10da6e25a380f88731
pull/17/head
James South 13 years ago
parent
commit
70f3e62ddc
  1. 21
      src/ImageProcessor.Web/Caching/CachedImage.cs
  2. 16
      src/ImageProcessor.Web/Caching/PersistantDictionary.cs
  3. 34
      src/ImageProcessor.Web/Caching/SQLContext.cs
  4. 4
      src/ImageProcessor.Web/ImageProcessor.Web.csproj

21
src/ImageProcessor.Web/Caching/CachedImage.cs

@ -17,35 +17,38 @@ namespace ImageProcessor.Web.Caching
/// <summary>
/// Describes a cached image
/// </summary>
internal sealed class CachedImage
public sealed class CachedImage
{
//[PrimaryKey, AutoIncrement]
//public int Id { get; set; }
/// <summary>
/// Gets or sets the id identifying the cached image.
/// </summary>
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
/// <summary>
/// Gets or sets the key identifying the cached image.
/// </summary>
[PrimaryKey]
internal string Key { get; set; }
[Unique]
public string Key { get; set; }
/// <summary>
/// Gets or sets the value of the cached image.
/// </summary>
internal string Path { get; set; }
public string Path { get; set; }
/// <summary>
/// Gets or sets the maximum age of the cached image in days.
/// </summary>
internal int MaxAge { get; set; }
public int MaxAge { get; set; }
/// <summary>
/// Gets or sets the last write time of the cached image.
/// </summary>
internal DateTime LastWriteTimeUtc { get; set; }
public DateTime LastWriteTimeUtc { get; set; }
/// <summary>
/// Gets or sets when the cached image should expire from the cache.
/// </summary>
internal DateTime ExpiresUtc { get; set; }
public DateTime ExpiresUtc { get; set; }
}
}

16
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;
}
/// <summary>
@ -97,7 +101,7 @@ namespace ImageProcessor.Web.Caching
public async Task<CachedImage> 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
/// <returns>
/// true, if the dictionary is saved to the file-system; otherwise, false.
/// </returns>
private async Task<bool> SaveCacheAsync(string key, CachedImage cachedImage, bool remove)
private async Task<int> SaveCacheAsync(string key, CachedImage cachedImage, bool remove)
{
try
{
@ -134,7 +138,7 @@ namespace ImageProcessor.Web.Caching
}
catch
{
return false;
return 0;
}
}

34
src/ImageProcessor.Web/Caching/SQLContext.cs

@ -119,7 +119,7 @@ namespace ImageProcessor.Web.Caching
/// <returns>
/// The true if the addition of the cached image is added; otherwise, false.
/// </returns>
internal static async Task<bool> AddImageAsync(CachedImage image)
internal static async Task<int> AddImageAsync(CachedImage image)
{
// Create Action delegate for AddImage.
return await TaskHelpers.Run(() => AddImage(image));
@ -134,7 +134,7 @@ namespace ImageProcessor.Web.Caching
/// <returns>
/// The true if the addition of the cached image is removed; otherwise, false.
/// </returns>
internal static async Task<bool> RemoveImageAsync(string key)
internal static async Task<int> RemoveImageAsync(string key)
{
// Create Action delegate for RemoveImage.
return await TaskHelpers.Run(() => RemoveImage(key));
@ -152,24 +152,21 @@ namespace ImageProcessor.Web.Caching
/// <returns>
/// The true if the addition of the cached image is added; otherwise, false.
/// </returns>
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
/// <returns>
/// The true if the addition of the cached image is removed; otherwise, false.
/// </returns>
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<CachedImage>(key);
connection.Dispose();
});
id = connection.Delete<CachedImage>(key);
connection.Dispose();
return true;
return id;
}
catch
{
return false;
return 0;
}
}
#endregion

4
src/ImageProcessor.Web/ImageProcessor.Web.csproj

@ -26,14 +26,14 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<DefineConstants>TRACE;USE_CSHARP_SQLITE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'All|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\All\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>

Loading…
Cancel
Save