Skip to content

Commit 98572b9

Browse files
author
Jeff Treuting
committed
Moving AbbFabric and Memcached providers into separate projects
This way the base repository is not dependent on those assemblies and can be used with inmemory or no caching providers out of the box. Then the separate dlls can be added for memcached or whatever you want to use. Also started messing with NuGet stuff so some smaple test packages are in the source now. References: http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package http://stackoverflow.com/questions/10240029/how-to-install-a-nuget-package-nupkg-file-locally
1 parent d321d67 commit 98572b9

25 files changed

Lines changed: 783 additions & 537 deletions

SharpRepository.Repository/Caching/AppFabricCachingProvider.cs renamed to SharpRepository.Caching.AppFabric/AppFabricCachingProvider.cs

Lines changed: 129 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,129 @@
1-
using System;
2-
using System.Runtime.Caching;
3-
using Microsoft.ApplicationServer.Caching;
4-
5-
// Reference: http://stackoverflow.com/questions/4739548/appfabric-caching-examples-using-c-sharp
6-
7-
namespace SharpRepository.Repository.Caching
8-
{
9-
/// <summary>
10-
/// Uses AppFabric Caching as the caching provider. <a href="http://msdn.microsoft.com/en-us/library/ff383731(v=azure.10).aspx">Get more info on AppFabric Caching</a>
11-
/// </summary>
12-
public class AppFabricCachingProvider : ICachingProvider
13-
{
14-
protected DataCacheFactory CacheFactory { get; set;}
15-
protected DataCache Cache { get; set; }
16-
17-
private static readonly object LockObject = new object();
18-
19-
/// <summary>
20-
/// Initializes a new instance of the <see cref="AppFabricCachingProvider"/> class.
21-
/// </summary>
22-
/// <param name="cacheName">Name of the cache.</param>
23-
public AppFabricCachingProvider(string cacheName = null)
24-
: this(new DataCacheFactory(), cacheName)
25-
{
26-
}
27-
28-
/// <summary>
29-
/// Initializes a new instance of the <see cref="AppFabricCachingProvider"/> class.
30-
/// </summary>
31-
/// <param name="configuration">The AbbFabric Caching configuration.</param>
32-
/// <param name="cacheName">Name of the cache.</param>
33-
public AppFabricCachingProvider(DataCacheFactoryConfiguration configuration, string cacheName = null)
34-
: this(new DataCacheFactory(configuration), cacheName)
35-
{
36-
if (configuration == null) throw new ArgumentNullException("configuration");
37-
}
38-
39-
/// <summary>
40-
/// Initializes a new instance of the <see cref="AppFabricCachingProvider"/> class.
41-
/// </summary>
42-
/// <param name="cacheFactory">The cache factory.</param>
43-
/// <param name="cacheName">Name of the cache.</param>
44-
public AppFabricCachingProvider(DataCacheFactory cacheFactory, string cacheName = null)
45-
{
46-
if (cacheFactory == null) throw new ArgumentNullException("cacheFactory");
47-
48-
CacheFactory = cacheFactory;
49-
50-
// TODO: don't know enough about AppFabric to know if we should use the GetDefaultCache() if no cache name provided, or if we should use our own name like SharpRepository
51-
Cache = String.IsNullOrEmpty(cacheName) ? cacheFactory.GetDefaultCache() : cacheFactory.GetCache(cacheName);
52-
}
53-
54-
public void Set<T>(string key, T value, CacheItemPriority priority = CacheItemPriority.Default, int? cacheTime = null)
55-
{
56-
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
57-
58-
if (!cacheTime.HasValue)
59-
{
60-
Cache.Put(key, value);
61-
}
62-
else
63-
{
64-
Cache.Put(key, value, TimeSpan.FromSeconds(cacheTime.Value));
65-
}
66-
}
67-
68-
public void Clear(string key)
69-
{
70-
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
71-
72-
Cache.Remove(key);
73-
}
74-
75-
public bool Exists(string key)
76-
{
77-
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
78-
79-
return Cache.Get(key) != null;
80-
}
81-
82-
public bool Get<T>(string key, out T value)
83-
{
84-
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
85-
86-
value = default(T);
87-
88-
try
89-
{
90-
var item = Cache.Get(key);
91-
if (item == null)
92-
return false;
93-
94-
value = (T)item;
95-
}
96-
catch (Exception)
97-
{
98-
return false;
99-
}
100-
101-
return true;
102-
}
103-
104-
public int Increment(string key, int defaultValue, int value, CacheItemPriority priority = CacheItemPriority.Default)
105-
{
106-
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
107-
108-
lock (LockObject)
109-
{
110-
int current;
111-
if (!Get(key, out current))
112-
{
113-
current = defaultValue;
114-
}
115-
116-
var newValue = current + value;
117-
Set(key, newValue, priority);
118-
return newValue;
119-
}
120-
}
121-
122-
public void Dispose()
123-
{
124-
Cache = null;
125-
CacheFactory.Dispose();
126-
}
127-
}
128-
}
1+
using System;
2+
using System.Runtime.Caching;
3+
using Microsoft.ApplicationServer.Caching;
4+
using SharpRepository.Repository.Caching;
5+
6+
// Reference: http://stackoverflow.com/questions/4739548/appfabric-caching-examples-using-c-sharp
7+
8+
namespace SharpRepository.Caching.AppFabric
9+
{
10+
/// <summary>
11+
/// Uses AppFabric Caching as the caching provider. <a href="http://msdn.microsoft.com/en-us/library/ff383731(v=azure.10).aspx">Get more info on AppFabric Caching</a>
12+
/// </summary>
13+
public class AppFabricCachingProvider : ICachingProvider
14+
{
15+
protected DataCacheFactory CacheFactory { get; set;}
16+
protected DataCache Cache { get; set; }
17+
18+
private static readonly object LockObject = new object();
19+
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="AppFabricCachingProvider"/> class.
22+
/// </summary>
23+
/// <param name="cacheName">Name of the cache.</param>
24+
public AppFabricCachingProvider(string cacheName = null)
25+
: this(new DataCacheFactory(), cacheName)
26+
{
27+
}
28+
29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="AppFabricCachingProvider"/> class.
31+
/// </summary>
32+
/// <param name="configuration">The AbbFabric Caching configuration.</param>
33+
/// <param name="cacheName">Name of the cache.</param>
34+
public AppFabricCachingProvider(DataCacheFactoryConfiguration configuration, string cacheName = null)
35+
: this(new DataCacheFactory(configuration), cacheName)
36+
{
37+
if (configuration == null) throw new ArgumentNullException("configuration");
38+
}
39+
40+
/// <summary>
41+
/// Initializes a new instance of the <see cref="AppFabricCachingProvider"/> class.
42+
/// </summary>
43+
/// <param name="cacheFactory">The cache factory.</param>
44+
/// <param name="cacheName">Name of the cache.</param>
45+
public AppFabricCachingProvider(DataCacheFactory cacheFactory, string cacheName = null)
46+
{
47+
if (cacheFactory == null) throw new ArgumentNullException("cacheFactory");
48+
49+
CacheFactory = cacheFactory;
50+
51+
// TODO: don't know enough about AppFabric to know if we should use the GetDefaultCache() if no cache name provided, or if we should use our own name like SharpRepository
52+
Cache = String.IsNullOrEmpty(cacheName) ? cacheFactory.GetDefaultCache() : cacheFactory.GetCache(cacheName);
53+
}
54+
55+
public void Set<T>(string key, T value, CacheItemPriority priority = CacheItemPriority.Default, int? cacheTime = null)
56+
{
57+
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
58+
59+
if (!cacheTime.HasValue)
60+
{
61+
Cache.Put(key, value);
62+
}
63+
else
64+
{
65+
Cache.Put(key, value, TimeSpan.FromSeconds(cacheTime.Value));
66+
}
67+
}
68+
69+
public void Clear(string key)
70+
{
71+
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
72+
73+
Cache.Remove(key);
74+
}
75+
76+
public bool Exists(string key)
77+
{
78+
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
79+
80+
return Cache.Get(key) != null;
81+
}
82+
83+
public bool Get<T>(string key, out T value)
84+
{
85+
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
86+
87+
value = default(T);
88+
89+
try
90+
{
91+
var item = Cache.Get(key);
92+
if (item == null)
93+
return false;
94+
95+
value = (T)item;
96+
}
97+
catch (Exception)
98+
{
99+
return false;
100+
}
101+
102+
return true;
103+
}
104+
105+
public int Increment(string key, int defaultValue, int value, CacheItemPriority priority = CacheItemPriority.Default)
106+
{
107+
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
108+
109+
lock (LockObject)
110+
{
111+
int current;
112+
if (!Get(key, out current))
113+
{
114+
current = defaultValue;
115+
}
116+
117+
var newValue = current + value;
118+
Set(key, newValue, priority);
119+
return newValue;
120+
}
121+
}
122+
123+
public void Dispose()
124+
{
125+
Cache = null;
126+
CacheFactory.Dispose();
127+
}
128+
}
129+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("SharpRepository.Caching.AppFabric")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("SharpRepository.Caching.AppFabric")]
13+
[assembly: AssemblyCopyright("Copyright © 2012")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("9a62addf-9f66-455b-91cb-b7a6b409682c")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{3583AEBE-F1B5-44D9-A0D2-4F6FA1F459CA}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>SharpRepository.Caching.AppFabric</RootNamespace>
11+
<AssemblyName>SharpRepository.Caching.AppFabric</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="Microsoft.ApplicationServer.Caching.Client">
34+
<HintPath>..\packages\ServerAppFabric.Client.1.1.2106\lib\Microsoft.ApplicationServer.Caching.Client.dll</HintPath>
35+
</Reference>
36+
<Reference Include="Microsoft.ApplicationServer.Caching.Core">
37+
<HintPath>..\packages\ServerAppFabric.Client.1.1.2106\lib\Microsoft.ApplicationServer.Caching.Core.dll</HintPath>
38+
</Reference>
39+
<Reference Include="System" />
40+
<Reference Include="System.Core" />
41+
<Reference Include="System.Runtime.Caching" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<Compile Include="AppFabricCachingProvider.cs" />
45+
<Compile Include="Properties\AssemblyInfo.cs" />
46+
</ItemGroup>
47+
<ItemGroup>
48+
<None Include="packages.config" />
49+
</ItemGroup>
50+
<ItemGroup>
51+
<ProjectReference Include="..\SharpRepository.Repository\SharpRepository.Repository.csproj">
52+
<Project>{710dee79-25ce-4f68-b8b1-d08a135ad154}</Project>
53+
<Name>SharpRepository.Repository</Name>
54+
</ProjectReference>
55+
</ItemGroup>
56+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
57+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
58+
Other similar extension points exist, see Microsoft.Common.targets.
59+
<Target Name="BeforeBuild">
60+
</Target>
61+
<Target Name="AfterBuild">
62+
</Target>
63+
-->
64+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="ServerAppFabric.Client" version="1.1.2106" targetFramework="net45" />
4+
</packages>

0 commit comments

Comments
 (0)