Skip to content

Commit 022f3ca

Browse files
committed
Merge pull request #15 from mikepugh/master
Adding Amazon Web Service DynamoDB Cache Client
2 parents ec60781 + c2cdf16 commit 022f3ca

8 files changed

Lines changed: 767 additions & 2 deletions

File tree

lib/AWSSDK.dll

3.61 MB
Binary file not shown.

src/ServiceStack.CacheAccess.AwsDynamoDb/DynamoDbCacheClient.cs

Lines changed: 448 additions & 0 deletions
Large diffs are not rendered by default.
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("ServiceStack.CacheAccess.AwsDynamoDb")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("ServiceStack.CacheAccess.AwsDynamoDb")]
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("95e6e10a-af25-42bb-8dbc-c1d817e2aaa6")]
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: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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>{29C23E7D-F41E-42DD-8426-9B5254840450}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>ServiceStack.CacheAccess.AwsDynamoDb</RootNamespace>
11+
<AssemblyName>ServiceStack.CacheAccess.AwsDynamoDb</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="AWSSDK, Version=1.5.6.0, Culture=neutral, PublicKeyToken=cd2d24cd2bace800, processorArchitecture=MSIL">
34+
<SpecificVersion>False</SpecificVersion>
35+
<HintPath>..\..\lib\AWSSDK.dll</HintPath>
36+
</Reference>
37+
<Reference Include="ServiceStack.Interfaces">
38+
<HintPath>..\..\lib\ServiceStack.Interfaces.dll</HintPath>
39+
</Reference>
40+
<Reference Include="ServiceStack.Text">
41+
<HintPath>..\..\lib\ServiceStack.Text.dll</HintPath>
42+
</Reference>
43+
<Reference Include="System" />
44+
<Reference Include="System.Core" />
45+
<Reference Include="System.Xml.Linq" />
46+
<Reference Include="System.Data.DataSetExtensions" />
47+
<Reference Include="Microsoft.CSharp" />
48+
<Reference Include="System.Data" />
49+
<Reference Include="System.Xml" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<Compile Include="DynamoDbCacheClient.cs" />
53+
<Compile Include="Properties\AssemblyInfo.cs" />
54+
</ItemGroup>
55+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
56+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
57+
Other similar extension points exist, see Microsoft.Common.targets.
58+
<Target Name="BeforeBuild">
59+
</Target>
60+
<Target Name="AfterBuild">
61+
</Target>
62+
-->
63+
</Project>

src/ServiceStack.Contrib.sln

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Microsoft Visual Studio Solution File, Format Version 11.00
2-
# Visual Studio 2010
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio 2012
33
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{1CA66D0F-9000-4AB6-A71A-4E64F1A391B8}"
44
EndProject
55
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceStack.Compression", "ServiceStack.Compression\ServiceStack.Compression.csproj", "{EC12FEF4-E335-4C9D-9AA0-764A2203C26F}"
@@ -24,6 +24,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceStack.CacheAccess.Me
2424
EndProject
2525
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceStack.CacheAccess.Azure", "ServiceStack.CacheAccess.Azure\ServiceStack.CacheAccess.Azure.csproj", "{08840867-041E-46A2-97C3-EA223161D942}"
2626
EndProject
27+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceStack.CacheAccess.AwsDynamoDb", "ServiceStack.CacheAccess.AwsDynamoDb\ServiceStack.CacheAccess.AwsDynamoDb.csproj", "{29C23E7D-F41E-42DD-8426-9B5254840450}"
28+
EndProject
29+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceStack.CacheAccess.AwsDynamoDb.Tests", "..\tests\ServiceStack.CacheAccess.AwsDynamoDb.Tests\ServiceStack.CacheAccess.AwsDynamoDb.Tests.csproj", "{27217138-EA6A-466F-83D4-A4585C921781}"
30+
EndProject
2731
Global
2832
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2933
Debug|Any CPU = Debug|Any CPU
@@ -80,11 +84,28 @@ Global
8084
{08840867-041E-46A2-97C3-EA223161D942}.Release|Any CPU.Build.0 = Release|Any CPU
8185
{08840867-041E-46A2-97C3-EA223161D942}.STATIC_ONLY NO_EXPRESSIONS|Any CPU.ActiveCfg = Release|Any CPU
8286
{08840867-041E-46A2-97C3-EA223161D942}.STATIC_ONLY NO_EXPRESSIONS|Any CPU.Build.0 = Release|Any CPU
87+
{29C23E7D-F41E-42DD-8426-9B5254840450}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
88+
{29C23E7D-F41E-42DD-8426-9B5254840450}.Debug|Any CPU.Build.0 = Debug|Any CPU
89+
{29C23E7D-F41E-42DD-8426-9B5254840450}.MonoTouch|Any CPU.ActiveCfg = Release|Any CPU
90+
{29C23E7D-F41E-42DD-8426-9B5254840450}.MonoTouch|Any CPU.Build.0 = Release|Any CPU
91+
{29C23E7D-F41E-42DD-8426-9B5254840450}.Release|Any CPU.ActiveCfg = Release|Any CPU
92+
{29C23E7D-F41E-42DD-8426-9B5254840450}.Release|Any CPU.Build.0 = Release|Any CPU
93+
{29C23E7D-F41E-42DD-8426-9B5254840450}.STATIC_ONLY NO_EXPRESSIONS|Any CPU.ActiveCfg = Release|Any CPU
94+
{29C23E7D-F41E-42DD-8426-9B5254840450}.STATIC_ONLY NO_EXPRESSIONS|Any CPU.Build.0 = Release|Any CPU
95+
{27217138-EA6A-466F-83D4-A4585C921781}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
96+
{27217138-EA6A-466F-83D4-A4585C921781}.Debug|Any CPU.Build.0 = Debug|Any CPU
97+
{27217138-EA6A-466F-83D4-A4585C921781}.MonoTouch|Any CPU.ActiveCfg = Release|Any CPU
98+
{27217138-EA6A-466F-83D4-A4585C921781}.MonoTouch|Any CPU.Build.0 = Release|Any CPU
99+
{27217138-EA6A-466F-83D4-A4585C921781}.Release|Any CPU.ActiveCfg = Release|Any CPU
100+
{27217138-EA6A-466F-83D4-A4585C921781}.Release|Any CPU.Build.0 = Release|Any CPU
101+
{27217138-EA6A-466F-83D4-A4585C921781}.STATIC_ONLY NO_EXPRESSIONS|Any CPU.ActiveCfg = Release|Any CPU
102+
{27217138-EA6A-466F-83D4-A4585C921781}.STATIC_ONLY NO_EXPRESSIONS|Any CPU.Build.0 = Release|Any CPU
83103
EndGlobalSection
84104
GlobalSection(SolutionProperties) = preSolution
85105
HideSolutionNode = FALSE
86106
EndGlobalSection
87107
GlobalSection(NestedProjects) = preSolution
88108
{3EEF88B9-14A0-466D-B364-24D5D0E9BE75} = {1CA66D0F-9000-4AB6-A71A-4E64F1A391B8}
109+
{27217138-EA6A-466F-83D4-A4585C921781} = {1CA66D0F-9000-4AB6-A71A-4E64F1A391B8}
89110
EndGlobalSection
90111
EndGlobal
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Amazon;
7+
using NUnit.Framework;
8+
9+
namespace ServiceStack.CacheAccess.AwsDynamoDb.Tests
10+
{
11+
[TestFixture]
12+
public class DynamoDbCacheClientTests
13+
{
14+
// Replace these with your prod/test AWS account to run unit tests.
15+
private const string yourAwsAccountKey = "SOME.KEY";
16+
private const string yourAwsSecretKey = "SOME.SECRET.KEY";
17+
18+
public class DummyObject
19+
{
20+
public string UserId { get; set; }
21+
public string Email { get; set; }
22+
public string Phone { get; set; }
23+
public List<string> Friends { get; set; }
24+
}
25+
26+
private ICacheClient _client;
27+
private DummyObject _item;
28+
private string _itemCacheKey = "urn:dummyobject:john.doe";
29+
private string _counterCacheKey = "urn:counter";
30+
31+
[SetUp]
32+
public void SetupTests()
33+
{
34+
35+
_client = new DynamoDbCacheClient(yourAwsAccountKey, yourAwsSecretKey,
36+
RegionEndpoint.USEast1, "ICacheClientDynamoDb", 10, 5, true);
37+
// The primary item we'll be caching in the tests.
38+
_item = new DummyObject
39+
{
40+
UserId = "john.doe",
41+
Email = "john.doe@servicestack.net",
42+
Phone = "555-555-9876",
43+
Friends = new List<string> {"jane.doe", "jack.doe", "some.friend"}
44+
};
45+
}
46+
47+
[Test]
48+
public void DyanmoDb_ExerciseCacheClient()
49+
{
50+
// Expecting the Set operation to succeed
51+
bool setResponse = _client.Set<DummyObject>(_itemCacheKey, _item);
52+
Assert.AreEqual(true, setResponse);
53+
54+
// Expecting the Get to return the item cached above
55+
var actual = _client.Get<DummyObject>(_itemCacheKey);
56+
Assert.IsNotNull(actual);
57+
Assert.AreEqual(_item.UserId, actual.UserId);
58+
59+
// Expecting Add to return false since the item is already cached
60+
bool addResponse = _client.Add<DummyObject>(_itemCacheKey, _item);
61+
Assert.AreEqual(false, addResponse);
62+
63+
// Expecting remove to succeed
64+
bool removeResponse = _client.Remove(_itemCacheKey);
65+
Assert.AreEqual(true, removeResponse);
66+
67+
// Add the item back, expecting success
68+
addResponse = _client.Add<DummyObject>(_itemCacheKey, _item);
69+
Assert.AreEqual(true, addResponse);
70+
71+
// Remove it again
72+
removeResponse = _client.Remove(_itemCacheKey);
73+
74+
// Clear the counter if it exists
75+
removeResponse = _client.Remove(_counterCacheKey);
76+
77+
// Initialize the counter, incResponse should be equal to 0 since the counter doesn't exist
78+
long incResponse = _client.Increment(_counterCacheKey, 0);
79+
80+
// Increment by 1
81+
long updatedIncResponse = _client.Increment(_counterCacheKey, 1);
82+
Assert.AreEqual(incResponse + 1, updatedIncResponse);
83+
// Decrement by 1
84+
long decResponse = _client.Decrement(_counterCacheKey, 1);
85+
Assert.AreEqual(incResponse, decResponse);
86+
87+
// Clear out the cache - this will cause a very long delete/re-create DynamoDB table sequence
88+
_client.FlushAll();
89+
90+
}
91+
}
92+
}
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("ServiceStack.CacheAccess.AwsDynamoDb.Tests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("ServiceStack.CacheAccess.AwsDynamoDb.Tests")]
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("96e25089-a6d1-45ba-944f-8c6461601b88")]
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: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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>{27217138-EA6A-466F-83D4-A4585C921781}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>ServiceStack.CacheAccess.AwsDynamoDb.Tests</RootNamespace>
11+
<AssemblyName>ServiceStack.CacheAccess.AwsDynamoDb.Tests</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="AWSSDK, Version=1.5.6.0, Culture=neutral, PublicKeyToken=cd2d24cd2bace800, processorArchitecture=MSIL">
34+
<SpecificVersion>False</SpecificVersion>
35+
<HintPath>..\..\lib\AWSSDK.dll</HintPath>
36+
</Reference>
37+
<Reference Include="nunit.framework">
38+
<HintPath>..\..\lib\tests\nunit.framework.dll</HintPath>
39+
</Reference>
40+
<Reference Include="ServiceStack.Interfaces">
41+
<HintPath>..\..\lib\ServiceStack.Interfaces.dll</HintPath>
42+
</Reference>
43+
<Reference Include="System" />
44+
<Reference Include="System.Core" />
45+
<Reference Include="System.Xml.Linq" />
46+
<Reference Include="System.Data.DataSetExtensions" />
47+
<Reference Include="Microsoft.CSharp" />
48+
<Reference Include="System.Data" />
49+
<Reference Include="System.Xml" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<Compile Include="DynamoDbCacheClientTests.cs" />
53+
<Compile Include="Properties\AssemblyInfo.cs" />
54+
</ItemGroup>
55+
<ItemGroup>
56+
<ProjectReference Include="..\..\src\ServiceStack.CacheAccess.AwsDynamoDb\ServiceStack.CacheAccess.AwsDynamoDb.csproj">
57+
<Project>{29c23e7d-f41e-42dd-8426-9b5254840450}</Project>
58+
<Name>ServiceStack.CacheAccess.AwsDynamoDb</Name>
59+
</ProjectReference>
60+
</ItemGroup>
61+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
62+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
63+
Other similar extension points exist, see Microsoft.Common.targets.
64+
<Target Name="BeforeBuild">
65+
</Target>
66+
<Target Name="AfterBuild">
67+
</Target>
68+
-->
69+
</Project>

0 commit comments

Comments
 (0)