Skip to content

Commit

Permalink
Merge pull request #25 from dennisdoomen/develop
Browse files Browse the repository at this point in the history
Release 1.0
  • Loading branch information
dennisdoomen authored Aug 10, 2016
2 parents 637e686 + e66462e commit f9a9ab0
Show file tree
Hide file tree
Showing 24 changed files with 236 additions and 143 deletions.
22 changes: 12 additions & 10 deletions Build/default.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,6 @@ task Compile {
}
}

task BuildPackage {
TeamCity-Block "Building NuGet Package" {
if (!(Test-Path "$ArtifactsDirectory\")) {
New-Item $ArtifactsDirectory -ItemType Directory
}

& $Nuget pack "$SrcDirectory\.nuspec" -o "$ArtifactsDirectory\"
}
}

task RunTests -depends Compile -Description "Running all unit tests." {
$xunitRunner = "$BaseDirectory\Packages\xunit.runner.console.2.0.0\tools\xunit.console.exe"

Expand All @@ -86,7 +76,19 @@ task RunTests -depends Compile -Description "Running all unit tests." {

exec { . $xunitRunner "$BaseDirectory\Tests\FluidCaching.Specs\bin\Release\FluidCaching.Specs.dll" -html "$ArtifactsDirectory\$project.html" }
}


task BuildPackage {
TeamCity-Block "Building NuGet Package" {
if (!(Test-Path "$ArtifactsDirectory\")) {
New-Item $ArtifactsDirectory -ItemType Directory
}

& "$ArtifactsDirectory\MergeCSharpFiles.exe" "$SrcDirectory\FluidCaching" *.cs "$ArtifactsDirectory\FluidCaching.cs"

& $Nuget pack "$SrcDirectory\.nuspec" -o "$ArtifactsDirectory\"
}
}

task PublishToMyget -precondition { return $NuGetPushSource -and $env:NuGetApiKey } {
TeamCity-Block "Publishing NuGet Package to Myget" {
Expand Down
12 changes: 6 additions & 6 deletions FluidCaching.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25029.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluidCaching", "Src\FluidCaching\FluidCaching.csproj", "{AECB5991-BDC6-4020-99E1-72631C545D75}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluidCaching.Specs", "Tests\FluidCaching.Specs\FluidCaching.Specs.csproj", "{61AC252D-B354-40E4-A9DA-78AB6CAFC162}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "Samples\ConsoleApp\ConsoleApp.csproj", "{6361D139-DC35-466A-860D-4FAD0C1D3105}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MergeCSharpFiles", "Src\MergeCSharpFiles\MergeCSharpFiles.csproj", "{3220F580-0239-4D63-B17C-5143F9BB1EB4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -23,10 +23,10 @@ Global
{61AC252D-B354-40E4-A9DA-78AB6CAFC162}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61AC252D-B354-40E4-A9DA-78AB6CAFC162}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61AC252D-B354-40E4-A9DA-78AB6CAFC162}.Release|Any CPU.Build.0 = Release|Any CPU
{6361D139-DC35-466A-860D-4FAD0C1D3105}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6361D139-DC35-466A-860D-4FAD0C1D3105}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6361D139-DC35-466A-860D-4FAD0C1D3105}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6361D139-DC35-466A-860D-4FAD0C1D3105}.Release|Any CPU.Build.0 = Release|Any CPU
{3220F580-0239-4D63-B17C-5143F9BB1EB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3220F580-0239-4D63-B17C-5143F9BB1EB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3220F580-0239-4D63-B17C-5143F9BB1EB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3220F580-0239-4D63-B17C-5143F9BB1EB4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
31 changes: 0 additions & 31 deletions Samples/ConsoleApp/Program.cs

This file was deleted.

4 changes: 0 additions & 4 deletions Samples/ConsoleApp/packages.config

This file was deleted.

11 changes: 6 additions & 5 deletions Src/.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
<metadata>
<id>FluidCaching.Sources</id>
<title>FluidCaching</title>
<version>0.1.0-fixcompile0001</version>
<version>0.1.0-mergefiles0001</version>
<owners>Dennis Doomen</owners>
<authors>Dennis Doomen</authors>
<summary>
TBD
A multi-threaded high performance Least Recently Used cache with async/await support, compiled for .NET Standard 1.1 and shipped as source-only NuGet package.
</summary>
<description>
TBD
A multi-threaded high performance Least Recently Used cache with async/await support, compiled for .NET Standard 1.1 and shipped as source-only NuGet package.
Read http://www.continuousimprover.com/2016/02/a-least-recently-used-cache-that-you.html for some background information.
</description>
<language>en-US</language>
<licenseUrl>https://github.com/dennisdoomen/FluidCaching</licenseUrl>
<projectUrl>https://github.com/dennisdoomen/FluidCaching</projectUrl>
<tags>LRU Caching</tags>
<copyright>Copyright Dennis Doomen 2015-2016</copyright>
<releaseNotes>
TBD
See https://github.com/dennisdoomen/FluidCaching/releases
</releaseNotes>
</metadata>
<files>
<file src="..\Src\FluidCaching\*.cs" target="content/App_Packages/FluidCaching.Sources" />
<file src="..\Artifacts\FluidCaching.cs" target="content/App_Packages/FluidCaching.Sources" />
</files>
</package>
31 changes: 30 additions & 1 deletion Src/FluidCaching/CacheStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

namespace FluidCaching
{
public class CacheStats
/// <summary>
/// Provides statistics about the cache.
/// </summary>
#if PUBLIC_FLUID_CACHING
public
#else
internal
#endif
class CacheStats
{
private int current;
private int totalCount;
Expand All @@ -14,6 +22,13 @@ internal CacheStats(int capacity)
Capacity = capacity;
}

/// <summary>
/// Gets a value indicating the maximum number of items the cache should support.
/// </summary>
/// <remarks>
/// The actual number of items can exceed the value of this property if certain items didn't reach the minimum
/// retention time.
/// </remarks>
public int Capacity { get; set; }

/// <summary>
Expand All @@ -26,10 +41,21 @@ internal CacheStats(int capacity)
/// </summary>
public int SinceCreation => totalCount;

/// <summary>
/// Gets the number of times an item was requested from the cache which did not exist yet, since the cache
/// was created.
/// </summary>
public long Misses => misses;

/// <summary>
/// Gets the number of times an existing item was requested from the cache since the cache
/// was created.
/// </summary>
public long Hits => hits;

/// <summary>
/// Resets the statistics.
/// </summary>
public void Reset()
{
totalCount = 0;
Expand Down Expand Up @@ -67,6 +93,9 @@ internal void MarkAsRebuild(int rebuildIndexSize)
current = rebuildIndexSize;
}

/// <summary>Returns a string that represents the current object.</summary>
/// <returns>A string that represents the current object.</returns>
/// <filterpriority>2</filterpriority>
public override string ToString()
{
return $"Capacity: {Capacity}, Current: {current}, Total: {totalCount}, Hits: {hits}, Misses: {misses}";
Expand Down
18 changes: 13 additions & 5 deletions Src/FluidCaching/FluidCache.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace FluidCaching
{
Expand All @@ -24,7 +25,13 @@ namespace FluidCaching
/// !!!!! THERE ARE 2 DIFFERENT LOCKS USED BY CACHE - so care is required when altering code or you may introduce deadlocks !!!!!
/// order of lock nesting is LifespanMgr (Monitor) / Index (ReaderWriterLock)
/// </remarks>
public class FluidCache<T> where T : class
#if PUBLIC_FLUID_CACHING
public
#else
internal
#endif

class FluidCache<T> where T : class
{
private readonly Dictionary<string, IIndexManagement<T>> indexList = new Dictionary<string, IIndexManagement<T>>();
private readonly LifespanManager<T> lifeSpan;
Expand All @@ -34,6 +41,7 @@ public class FluidCache<T> where T : class
/// <param name="minAge">the minimium time after an access before an item becomes eligible for removal, during this time
/// the item is protected and will not be removed from cache even if over capacity</param>
/// <param name="maxAge">the max time that an object will sit in the cache without being accessed, before being removed</param>
/// <param name="getNow">A delegate to get the current time.</param>
/// <param name="validateCache">
/// An optional delegate used to determine if cache is out of date. Is called before index access not more than once per 10 seconds
/// </param>
Expand All @@ -58,19 +66,19 @@ public IIndex<TKey, T> GetIndex<TKey>(string indexName)
}

/// <summary>Retrieve a object by index name / key</summary>
public T Get<TKey>(string indexName, TKey key, ItemLoader<TKey, T> item = null)
public Task<T> Get<TKey>(string indexName, TKey key, ItemCreator<TKey, T> item = null)
{
IIndex<TKey, T> index = GetIndex<TKey>(indexName);
return index?.GetItem(key, item);
}

/// <summary>AddAsNode a new index to the cache</summary>
/// <summary>AddAsNode a new index to the cache</summary>
/// <typeparam name="TKey">the type of the key value</typeparam>
/// <param name="indexName">the name to be associated with this list</param>
/// <param name="getKey">delegate to get key from object</param>
/// <param name="item">delegate to load object if it is not found in index</param>
/// <returns>the newly created index</returns>
public IIndex<TKey, T> AddIndex<TKey>(string indexName, GetKey<T, TKey> getKey, ItemLoader<TKey, T> item = null)
public IIndex<TKey, T> AddIndex<TKey>(string indexName, GetKey<T, TKey> getKey, ItemCreator<TKey, T> item = null)
{
var index = new Index<TKey, T>(this, lifeSpan, getKey, item);
indexList[indexName] = index;
Expand All @@ -82,7 +90,7 @@ public IIndex<TKey, T> AddIndex<TKey>(string indexName, GetKey<T, TKey> getKey,
/// </summary>
public void Add(T item)
{
Add(item);
AddAsNode(item);
}

/// <summary>
Expand Down
10 changes: 7 additions & 3 deletions Src/FluidCaching/FluidCaching.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG;PUBLIC_FLUID_CACHING</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>bin\Debug\FluidCaching.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<DefineConstants>TRACE;PUBLIC_FLUID_CACHING</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>bin\Release\FluidCaching.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="AgeBag.cs" />
Expand All @@ -45,7 +49,7 @@
<Compile Include="Index.cs" />
<Compile Include="INode.cs" />
<Compile Include="IsValid.cs" />
<Compile Include="ItemLoader.cs" />
<Compile Include="ItemCreator.cs" />
<Compile Include="LifespanManager.cs" />
<Compile Include="Node.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
11 changes: 10 additions & 1 deletion Src/FluidCaching/GetKey.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
namespace FluidCaching
{
public delegate TKey GetKey<T, TKey>(T item) where T : class;
/// <summary>
/// Represents a delegate that the cache uses to obtain the key from a cachable item.
/// </summary>
#if PUBLIC_FLUID_CACHING
public
#else
internal
#endif

delegate TKey GetKey<T, TKey>(T item) where T : class;
}
12 changes: 11 additions & 1 deletion Src/FluidCaching/GetNow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,15 @@

namespace FluidCaching
{
public delegate DateTime GetNow();
/// <summary>
/// Represents a delegate to get the current time in a unit test-friendly way.
/// </summary>
/// <returns></returns>
#if PUBLIC_FLUID_CACHING
public
#else
internal
#endif

delegate DateTime GetNow();
}
13 changes: 9 additions & 4 deletions Src/FluidCaching/IIndex.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
using System.Threading.Tasks;

namespace FluidCaching
{
/// <summary>
/// The public wrapper for a Index
/// </summary>
public interface IIndex<TKey, T> where T : class
#if PUBLIC_FLUID_CACHING
public
#else
internal
#endif
interface IIndex<TKey, T> where T : class
{
/// <summary>
/// Getter for index
Expand All @@ -13,12 +20,10 @@ public interface IIndex<TKey, T> where T : class
/// An optional delegate that is used to create the actual object if it doesn't exist in the cache.
/// </param>
/// <returns>the object value associated with the cache</returns>
T GetItem(TKey key, ItemLoader<TKey, T> createItem = null);
Task<T> GetItem(TKey key, ItemCreator<TKey, T> createItem = null);

/// <summary>Delete object that matches key from cache</summary>
/// <param name="key">key to find</param>
void Remove(TKey key);

long Count { get; }
}
}
Loading

0 comments on commit f9a9ab0

Please sign in to comment.