Skip to content

Commit 5cbf2ab

Browse files
committed
Merge in original work from old repo
Conflicts: LICENSE
2 parents 5d26caf + 2976190 commit 5cbf2ab

218 files changed

Lines changed: 26661 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
bin/
2+
obj/
3+
TestResult.xml
4+
TestResult.formatted.xml
5+
*.pidb
6+
*.VisualState.xml
7+
*.userprefs
8+
*.orig
9+
*.directory

COPYING

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Please see LICENSE for a copy of the MIT license, under which this
2+
software is released.
3+
4+
List of contributors
5+
--------------------
6+
Craig Fowler - CSF Software Limited

CSF.Caches/CSF.Caches.csproj

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{6644C95A-70A7-4A7B-903D-E087037FDA26}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<RootNamespace>CSF.Caches</RootNamespace>
11+
<AssemblyName>CSF.Caches</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
</PropertyGroup>
14+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
15+
<DebugSymbols>true</DebugSymbols>
16+
<DebugType>full</DebugType>
17+
<Optimize>false</Optimize>
18+
<OutputPath>bin\Debug</OutputPath>
19+
<DefineConstants>DEBUG;</DefineConstants>
20+
<ErrorReport>prompt</ErrorReport>
21+
<WarningLevel>4</WarningLevel>
22+
<ConsolePause>false</ConsolePause>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>full</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release</OutputPath>
28+
<ErrorReport>prompt</ErrorReport>
29+
<WarningLevel>4</WarningLevel>
30+
<ConsolePause>false</ConsolePause>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="System" />
34+
</ItemGroup>
35+
<ItemGroup>
36+
<Compile Include="Properties\AssemblyInfo.cs" />
37+
<Compile Include="ICache.cs" />
38+
<Compile Include="ThreadSafeCache.cs" />
39+
<Compile Include="NotAvailableInCacheException.cs" />
40+
</ItemGroup>
41+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
42+
</Project>

CSF.Caches/ICache.cs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
//
2+
// ICache.cs
3+
//
4+
// Author:
5+
// Craig Fowler <craig@csf-dev.com>
6+
//
7+
// Copyright (c) 2015 CSF Software Limited
8+
//
9+
// Permission is hereby granted, free of charge, to any person obtaining a copy
10+
// of this software and associated documentation files (the "Software"), to deal
11+
// in the Software without restriction, including without limitation the rights
12+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
// copies of the Software, and to permit persons to whom the Software is
14+
// furnished to do so, subject to the following conditions:
15+
//
16+
// The above copyright notice and this permission notice shall be included in
17+
// all copies or substantial portions of the Software.
18+
//
19+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
// THE SOFTWARE.
26+
27+
using System;
28+
29+
namespace CSF.Caches
30+
{
31+
/// <summary>
32+
/// Interface for a cache implementation, which caches instances of <typeparamref name="TValue" /> indexed by a
33+
/// <typeparamref name="TKey" />.
34+
/// </summary>
35+
public interface ICache<TKey,TValue>
36+
{
37+
#region methods
38+
39+
/// <summary>
40+
/// Adds an item to the cache.
41+
/// </summary>
42+
/// <remarks>
43+
/// <para>
44+
/// If an item already exists within the cache, identified by the given key, then the value is not added to the
45+
/// cache, and <c>false</c> is returned.
46+
/// </para>
47+
/// </remarks>
48+
/// <returns><c>true</c> if a new item was added to the cache; <c>false</c> if not.</returns>
49+
/// <param name="key">The key at which to store the value.</param>
50+
/// <param name="value">The value to store.</param>
51+
bool Add(TKey key, TValue value);
52+
53+
/// <summary>
54+
/// Removes an item from the cache.
55+
/// </summary>
56+
/// <remarks>
57+
/// <para>
58+
/// If an item does not exist within the cache, identified by the given key, then nothing is removed and
59+
/// <c>false</c> is returned.
60+
/// </para>
61+
/// </remarks>
62+
/// <returns><c>true</c> if a an item was removed; <c>false</c> if not.</returns>
63+
/// <param name="key">The key at which to remove an item.</param>
64+
bool Remove(TKey key);
65+
66+
/// <summary>
67+
/// Gets a value indicating whether the cache contains an item identified by the given key.
68+
/// </summary>
69+
/// <param name="key">The key at which to search for an item.</param>
70+
bool Contains(TKey key);
71+
72+
/// <summary>
73+
/// Attempts to get a value from the cache.
74+
/// </summary>
75+
/// <returns><c>true</c>, if a value was found in the cache, <c>false</c> otherwise.</returns>
76+
/// <param name="key">The key for which to retrieve a value.</param>
77+
/// <param name="value">Exposes the value retrieved from the cache. The value of this parameter is undefined if no value was found.</param>
78+
bool TryGet(TKey key, out TValue value);
79+
80+
/// <summary>
81+
/// Gets a value from the cache, raising an exception if no value is available.
82+
/// </summary>
83+
/// <exception cref="NotAvailableInCacheException">If the cache does not contain a value for the given key.</exception>
84+
/// <param name="key">The key at which to get a value.</param>
85+
TValue Get(TKey key);
86+
87+
/// <summary>
88+
/// Attempts to get a value from the cache, executing a function to create a value (and add that to the cache) if
89+
/// one is not already contained.
90+
/// </summary>
91+
/// <returns>The cached value, or the newly-created/added one.</returns>
92+
/// <param name="key">The key for the value.</param>
93+
/// <param name="valueFactory">A delegate with which to create an instance of the value if it is required.</param>
94+
TValue GetOrAdd(TKey key, Func<TValue> valueFactory);
95+
96+
/// <summary>
97+
/// Attempts to get a value from the cache, executing a function to create a value (and add that to the cache) if
98+
/// one is not already contained.
99+
/// </summary>
100+
/// <remarks>
101+
/// <para>
102+
/// The <paramref name="cacheHit"/> parameter will be set to <c>true</c> if the request was fulfilled from the
103+
/// cache, or <c>false</c> if the <paramref name="valueFactory"/> was invoked in order to create a value for the
104+
/// cache.
105+
/// </para>
106+
/// </remarks>
107+
/// <returns>The cached value, or the newly-created/added one.</returns>
108+
/// <param name="key">The key for the value.</param>
109+
/// <param name="valueFactory">A delegate with which to create an instance of the value if it is required.</param>
110+
/// <param name="cacheHit">Exposes a value indicating whether or not the result was a cache 'hit'.</param>
111+
TValue GetOrAdd(TKey key, Func<TValue> valueFactory, out bool cacheHit);
112+
113+
#endregion
114+
}
115+
}
116+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//
2+
// NotAvailableInCacheException.cs
3+
//
4+
// Author:
5+
// Craig Fowler <craig@csf-dev.com>
6+
//
7+
// Copyright (c) 2015 CSF Software Limited
8+
//
9+
// Permission is hereby granted, free of charge, to any person obtaining a copy
10+
// of this software and associated documentation files (the "Software"), to deal
11+
// in the Software without restriction, including without limitation the rights
12+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
// copies of the Software, and to permit persons to whom the Software is
14+
// furnished to do so, subject to the following conditions:
15+
//
16+
// The above copyright notice and this permission notice shall be included in
17+
// all copies or substantial portions of the Software.
18+
//
19+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
// THE SOFTWARE.
26+
27+
using System;
28+
29+
namespace CSF.Caches
30+
{
31+
/// <summary>
32+
/// Exception raised by an <see cref="T:ICache{TKey,TValue}"/> when a required value is not present in the cache.
33+
/// </summary>
34+
[Serializable]
35+
public class NotAvailableInCacheException : Exception
36+
{
37+
/// <summary>
38+
/// Initializes a new instance of the <see cref="T:NotAvailableInCacheException"/> class
39+
/// </summary>
40+
public NotAvailableInCacheException()
41+
{
42+
}
43+
44+
/// <summary>
45+
/// Initializes a new instance of the <see cref="T:NotAvailableInCacheException"/> class
46+
/// </summary>
47+
/// <param name="message">A <see cref="T:System.String"/> that describes the exception. </param>
48+
public NotAvailableInCacheException(string message) : base(message)
49+
{
50+
}
51+
52+
/// <summary>
53+
/// Initializes a new instance of the <see cref="T:NotAvailableInCacheException"/> class
54+
/// </summary>
55+
/// <param name="message">A <see cref="T:System.String"/> that describes the exception. </param>
56+
/// <param name="inner">The exception that is the cause of the current exception. </param>
57+
public NotAvailableInCacheException(string message, Exception inner) : base(message, inner)
58+
{
59+
}
60+
61+
/// <summary>
62+
/// Initializes a new instance of the <see cref="T:NotAvailableInCacheException"/> class
63+
/// </summary>
64+
/// <param name="context">The contextual information about the source or destination.</param>
65+
/// <param name="info">The object that holds the serialized object data.</param>
66+
protected NotAvailableInCacheException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context)
67+
{
68+
}
69+
}
70+
}
71+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// AssemblyInfo.cs
3+
//
4+
// Author:
5+
// Craig Fowler <craig@craigfowler.me.uk>
6+
//
7+
// Copyright (c) 2016 Craig Fowler
8+
//
9+
// Permission is hereby granted, free of charge, to any person obtaining a copy
10+
// of this software and associated documentation files (the "Software"), to deal
11+
// in the Software without restriction, including without limitation the rights
12+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
// copies of the Software, and to permit persons to whom the Software is
14+
// furnished to do so, subject to the following conditions:
15+
//
16+
// The above copyright notice and this permission notice shall be included in
17+
// all copies or substantial portions of the Software.
18+
//
19+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
// THE SOFTWARE.
26+
using System.Reflection;
27+
using System.Runtime.CompilerServices;
28+
29+
// Information about this assembly is defined by the following attributes.
30+
// Change them to the values specific to your project.
31+
32+
[assembly: AssemblyTitle("CSF.Caches")]
33+
[assembly: AssemblyDescription("")]
34+
[assembly: AssemblyConfiguration("")]
35+
[assembly: AssemblyCompany("CSF Software Limited")]
36+
[assembly: AssemblyProduct("")]
37+
[assembly: AssemblyCopyright("Craig Fowler")]
38+
[assembly: AssemblyTrademark("")]
39+
[assembly: AssemblyCulture("")]
40+
41+
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
42+
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
43+
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
44+
45+
[assembly: AssemblyVersion("1.0.*")]
46+
47+
// The following attributes are used to specify the signing key for the assembly,
48+
// if desired. See the Mono documentation for more information about signing.
49+
50+
//[assembly: AssemblyDelaySign(false)]
51+
//[assembly: AssemblyKeyFile("")]
52+

0 commit comments

Comments
 (0)