├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── WebAPI.OutputCache.Redis.Tests ├── Methods │ ├── AddTests.cs │ ├── ContainsTests.cs │ ├── GetGenericTests.cs │ ├── GetTests.cs │ └── RemoveTests.cs ├── Properties │ └── AssemblyInfo.cs ├── UserFixture.cs ├── WebAPI.OutputCache.Redis.Tests.csproj ├── app.config └── packages.config ├── WebAPI.OutputCache.Redis.sln ├── WebAPI.OutputCache.Redis ├── IJsonSerializer.cs ├── IRedisConnectionSettings.cs ├── JsonSerializer.cs ├── Properties │ └── AssemblyInfo.cs ├── RedisConnectionSettings.cs ├── RedisOutputCache.cs ├── WebAPI.OutputCache.Redis.csproj ├── WebAPI.OutputCache.Redis.nuspec └── packages.config └── appveyor.yml /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 2 | [Bb]in/ 3 | [Oo]bj/ 4 | [Aa]pp_Data/ 5 | # Nuget Packages folder 6 | [Pp]ackages/ 7 | # BuildArtifacts folder 8 | [Bb]uildArtifacts/ 9 | 10 | # mstest test results 11 | TestResults 12 | 13 | ## Ignore Visual Studio temporary files, build results, and 14 | ## files generated by popular Visual Studio add-ons. 15 | 16 | # User-specific files 17 | *.suo 18 | *.user 19 | *.sln.docstates 20 | 21 | #C9 Folder 22 | .c9/ 23 | # Build results 24 | [Dd]ebug/ 25 | [Rr]elease/ 26 | x64/ 27 | *_i.c 28 | *_p.c 29 | *.ilk 30 | *.meta 31 | *.obj 32 | *.pch 33 | *.pdb 34 | *.pgc 35 | *.pgd 36 | *.rsp 37 | *.sbr 38 | *.tlb 39 | *.tli 40 | *.tlh 41 | *.tmp 42 | *.vspscc 43 | *.vssscc 44 | .builds 45 | 46 | # Visual C++ cache files 47 | ipch/ 48 | *.aps 49 | *.ncb 50 | *.opensdf 51 | *.sdf 52 | 53 | # Visual Studio profiler 54 | *.psess 55 | *.vsp 56 | 57 | # Guidance Automation Toolkit 58 | *.gpState 59 | 60 | # ReSharper is a .NET coding add-in 61 | _ReSharper* 62 | 63 | # NCrunch 64 | *.ncrunch* 65 | .*crunch*.local.xml 66 | 67 | # Installshield output folder 68 | [Ee]xpress 69 | 70 | # DocProject is a documentation generator add-in 71 | DocProject/buildhelp/ 72 | DocProject/Help/*.HxT 73 | DocProject/Help/*.HxC 74 | DocProject/Help/*.hhc 75 | DocProject/Help/*.hhk 76 | DocProject/Help/*.hhp 77 | DocProject/Help/Html2 78 | DocProject/Help/html 79 | 80 | # Click-Once directory 81 | publish 82 | 83 | # Publish Web Output 84 | *.Publish.xml 85 | 86 | # Others 87 | [Bb]in 88 | [Oo]bj 89 | sql 90 | TestResults 91 | [Tt]est[Rr]esult* 92 | *.Cache 93 | ClientBin 94 | [Ss]tyle[Cc]op.* 95 | ~$* 96 | *.dbmdl 97 | Generated_Code #added for RIA/Silverlight projects 98 | 99 | # Backup & report files from converting an old project file to a newer 100 | # Visual Studio version. Backup files are not needed, because we have git ;-) 101 | _UpgradeReport_Files/ 102 | Backup*/ 103 | UpgradeLog*.XML 104 | *.nupkg 105 | .vs 106 | .idea/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Ziya SARIKAYA 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ASP.NET Web API CacheOutput - Redis 2 | 3 | Redis `provider` for AspNetWebApi-OutputCache 4 | Implementation of IApiOutputCache for Redis 5 | 6 | ## Sample 7 | 8 | You can register your implementation using a handy GlobalConfiguration extension method: 9 | 10 | ```csharp 11 | var _connectionSettings = new RedisConnectionSettings { ConnectionString = "localhost:6379", Db = 2 }; 12 | var mycache = new RedisOutputCache(new JsonSerializer(), _connectionSettings); 13 | 14 | //instance 15 | configuration.CacheOutputConfiguration().RegisterCacheOutputProvider(() => mycache); 16 | ``` 17 | 18 | For more information; 19 | https://github.com/filipw/Strathweb.CacheOutput#server-side-caching 20 | 21 | ### License 22 | MIT 23 | -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis.Tests/Methods/AddTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Common.Testing.NUnit; 3 | using FluentAssertions; 4 | using NUnit.Framework; 5 | using Ploeh.AutoFixture; 6 | using StackExchange.Redis; 7 | 8 | namespace WebAPI.OutputCache.Redis.Tests.Methods 9 | { 10 | [TestFixture] 11 | public class AddTests : TestBase 12 | { 13 | protected RedisOutputCache RedisApiOutputCache; 14 | IRedisConnectionSettings _connectionSettings; 15 | ConnectionMultiplexer _multiplexer; 16 | 17 | [TestFixtureSetUp] 18 | public void TestFixtureSetup() 19 | { 20 | _connectionSettings = new RedisConnectionSettings { ConnectionString = "localhost:6379", Db = 2 }; 21 | _multiplexer = ConnectionMultiplexer.Connect(_connectionSettings.ConnectionString); 22 | } 23 | 24 | protected override void FinalizeSetUp() 25 | { 26 | RedisApiOutputCache = new RedisOutputCache(new JsonSerializer(), _connectionSettings); 27 | 28 | } 29 | 30 | private void ClearDb() 31 | { 32 | _multiplexer.GetServer(_connectionSettings.ConnectionString).FlushDatabase(_connectionSettings.Db); 33 | } 34 | 35 | [Test] 36 | public void adds_item_to_cache() 37 | { 38 | //ClearDb(); 39 | var fixture = FixtureRepository.Create(); 40 | string key = fixture.Id.ToString(); 41 | 42 | RedisApiOutputCache.Add(key, fixture, DateTime.Now.AddSeconds(60)); 43 | var result = RedisApiOutputCache.Get(key); 44 | 45 | result.Should().NotBeNull(); 46 | result.Id.ShouldBeEquivalentTo(fixture.Id); 47 | result.Name.ShouldBeEquivalentTo(fixture.Name); 48 | 49 | 50 | } 51 | 52 | [Test] 53 | public void added_item_stored_with_expiry() 54 | { 55 | var fixture = FixtureRepository.Create(); 56 | 57 | var key = fixture.Id.ToString(); 58 | 59 | var expiration = DateTime.Now.AddSeconds(60); 60 | 61 | fixture.ExpireAt = expiration; 62 | 63 | RedisApiOutputCache.Add(fixture.Id.ToString(), fixture, expiration); 64 | 65 | var result = RedisApiOutputCache.Get(key); 66 | 67 | //todo: would be good to check they are the same value.. without this rubbish! 68 | //TODO: Jil seralize date as UTC by default, here is more detail https://github.com/kevin-montrose/Jil/issues/129 69 | expiration.Day.ShouldBeEquivalentTo(result.ExpireAt.Day); 70 | expiration.Month.ShouldBeEquivalentTo(result.ExpireAt.Month); 71 | expiration.Year.ShouldBeEquivalentTo(result.ExpireAt.Year); 72 | expiration.Hour.ShouldBeEquivalentTo(result.ExpireAt.Hour); 73 | expiration.Minute.ShouldBeEquivalentTo(result.ExpireAt.Minute); 74 | expiration.Second.ShouldBeEquivalentTo(result.ExpireAt.Second); 75 | expiration.Millisecond.ShouldBeEquivalentTo(result.ExpireAt.Millisecond); 76 | } 77 | 78 | [Test] 79 | public void adding_item_with_duplicate_key_updates_original() 80 | { 81 | var fixture = FixtureRepository.Create(); 82 | 83 | var key = "user"; 84 | 85 | RedisApiOutputCache.Add(key, fixture, DateTime.Now.AddSeconds(60)); 86 | 87 | var differentUser = FixtureRepository.Create(); 88 | 89 | RedisApiOutputCache.Add(key, differentUser, DateTime.Now.AddSeconds(60)); 90 | 91 | var result = RedisApiOutputCache.Get(key); 92 | 93 | result.Should().NotBeNull(); 94 | result.Id.ShouldBeEquivalentTo(differentUser.Id); 95 | result.Name.ShouldBeEquivalentTo(differentUser.Name); 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis.Tests/Methods/ContainsTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Common.Testing.NUnit; 3 | using FluentAssertions; 4 | using NUnit.Framework; 5 | using Ploeh.AutoFixture; 6 | using StackExchange.Redis; 7 | 8 | namespace WebAPI.OutputCache.Redis.Tests.Methods 9 | { 10 | [TestFixture] 11 | public class ContainsTests : TestBase 12 | { 13 | protected RedisOutputCache RedisApiOutputCache; 14 | IRedisConnectionSettings _connectionSettings; 15 | ConnectionMultiplexer _multiplexer; 16 | UserFixture _fixture; 17 | 18 | [TestFixtureSetUp] 19 | public void TestFixtureSetup() 20 | { 21 | _connectionSettings = new RedisConnectionSettings { ConnectionString = "localhost:6379", Db = 2 }; 22 | _multiplexer = ConnectionMultiplexer.Connect(_connectionSettings.ConnectionString); 23 | } 24 | 25 | protected override void FinalizeSetUp() 26 | { 27 | _fixture = FixtureRepository.Create(); 28 | 29 | RedisApiOutputCache = new RedisOutputCache(new JsonSerializer(), _connectionSettings); 30 | 31 | RedisApiOutputCache.Add(_fixture.Id.ToString(), _fixture, DateTime.Now.AddSeconds(60)); 32 | 33 | } 34 | 35 | private void ClearDb() 36 | { 37 | _multiplexer.GetServer(_connectionSettings.ConnectionString).FlushDatabase(_connectionSettings.Db); 38 | } 39 | 40 | 41 | [Test] 42 | public void removes_item_from_cache() 43 | { 44 | bool result = RedisApiOutputCache.Contains(_fixture.Id.ToString()); 45 | 46 | result.Should().BeTrue(); 47 | } 48 | 49 | [Test] 50 | public void returns_false_if_item_is_not_in_collection() 51 | { 52 | var result = RedisApiOutputCache.Contains("I_AM_A_BAD_KEY"); 53 | 54 | result.Should().BeFalse(); 55 | } 56 | 57 | } 58 | } -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis.Tests/Methods/GetGenericTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using Common.Testing.NUnit; 4 | using FluentAssertions; 5 | using NUnit.Framework; 6 | using Ploeh.AutoFixture; 7 | using StackExchange.Redis; 8 | 9 | namespace WebAPI.OutputCache.Redis.Tests.Methods 10 | { 11 | [TestFixture] 12 | public class GetGenericTests : TestBase 13 | { 14 | protected RedisOutputCache RedisApiOutputCache; 15 | IRedisConnectionSettings _connectionSettings; 16 | ConnectionMultiplexer _multiplexer; 17 | 18 | [TestFixtureSetUp] 19 | public void TestFixtureSetup() 20 | { 21 | _connectionSettings = new RedisConnectionSettings { ConnectionString = "localhost:6379", Db = 2 }; 22 | _multiplexer = ConnectionMultiplexer.Connect(_connectionSettings.ConnectionString); 23 | } 24 | 25 | protected override void FinalizeSetUp() 26 | { 27 | RedisApiOutputCache = new RedisOutputCache(new JsonSerializer(), _connectionSettings); 28 | } 29 | 30 | private void ClearDb() 31 | { 32 | _multiplexer.GetServer(_connectionSettings.ConnectionString).FlushDatabase(_connectionSettings.Db); 33 | } 34 | 35 | 36 | [Test] 37 | public void retrieves_item_from_cache() 38 | { 39 | var fixture = FixtureRepository.Create(); 40 | RedisApiOutputCache.Add(fixture.Id.ToString(), fixture, DateTime.Now.AddSeconds(60)); 41 | var result = RedisApiOutputCache.Get(fixture.Id.ToString()); 42 | 43 | result.Should().NotBeNull(); 44 | result.Should().BeOfType(); 45 | 46 | result.Id.ShouldBeEquivalentTo(fixture.Id); 47 | result.Name.ShouldBeEquivalentTo(fixture.Name); 48 | 49 | result.DateOfBirth.Day.ShouldBeEquivalentTo(fixture.DateOfBirth.Day); 50 | result.DateOfBirth.Month.ShouldBeEquivalentTo(fixture.DateOfBirth.Month); 51 | result.DateOfBirth.Year.ShouldBeEquivalentTo(fixture.DateOfBirth.Year); 52 | 53 | } 54 | 55 | [Test] 56 | public void returns_null_if_item_not_in_collection() 57 | { 58 | var result = RedisApiOutputCache.Get("unknown key"); 59 | 60 | result.Should().BeNull(); 61 | } 62 | 63 | [Test] 64 | public void does_not_return_item_that_has_expired() 65 | { 66 | //TODO: FIX ME 67 | var fixture = FixtureRepository.Create(); 68 | RedisApiOutputCache.Add("expired-item", fixture, DateTime.Now.AddSeconds(3)); 69 | 70 | Thread.Sleep(TimeSpan.FromSeconds(5)); 71 | 72 | var result = RedisApiOutputCache.Get("expired-item"); 73 | 74 | result.Should().BeNull(); 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis.Tests/Methods/GetTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Common.Testing.NUnit; 3 | using FluentAssertions; 4 | using NUnit.Framework; 5 | using Ploeh.AutoFixture; 6 | using StackExchange.Redis; 7 | 8 | namespace WebAPI.OutputCache.Redis.Tests.Methods 9 | { 10 | [TestFixture] 11 | public class GetTests : TestBase 12 | { 13 | protected RedisOutputCache RedisApiOutputCache; 14 | IRedisConnectionSettings _connectionSettings; 15 | ConnectionMultiplexer _multiplexer; 16 | UserFixture _fixture; 17 | 18 | [TestFixtureSetUp] 19 | public void TestFixtureSetup() 20 | { 21 | _connectionSettings = new RedisConnectionSettings { ConnectionString = "localhost:6379", Db = 2 }; 22 | _multiplexer = ConnectionMultiplexer.Connect(_connectionSettings.ConnectionString); 23 | } 24 | 25 | protected override void FinalizeSetUp() 26 | { 27 | _fixture = FixtureRepository.Create(); 28 | RedisApiOutputCache = new RedisOutputCache(new JsonSerializer(), _connectionSettings); 29 | RedisApiOutputCache.Add(_fixture.Id.ToString(), _fixture, DateTime.Now.AddSeconds(60)); 30 | 31 | } 32 | 33 | private void ClearDb() 34 | { 35 | _multiplexer.GetServer(_connectionSettings.ConnectionString).FlushDatabase(_connectionSettings.Db); 36 | } 37 | 38 | [Test] 39 | public void retrieves_item_from_cache() 40 | { 41 | var result = RedisApiOutputCache.Get(_fixture.Id.ToString()); 42 | 43 | result.Should().NotBeNull(); 44 | result.Id.ShouldBeEquivalentTo(_fixture.Id); 45 | result.Name.ShouldBeEquivalentTo(_fixture.Name); 46 | 47 | result.DateOfBirth.Day.ShouldBeEquivalentTo(_fixture.DateOfBirth.Day); 48 | result.DateOfBirth.Month.ShouldBeEquivalentTo(_fixture.DateOfBirth.Month); 49 | result.DateOfBirth.Year.ShouldBeEquivalentTo(_fixture.DateOfBirth.Year); 50 | 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis.Tests/Methods/RemoveTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Common.Testing.NUnit; 3 | using FluentAssertions; 4 | using NUnit.Framework; 5 | using Ploeh.AutoFixture; 6 | using StackExchange.Redis; 7 | 8 | namespace WebAPI.OutputCache.Redis.Tests.Methods 9 | { 10 | [TestFixture] 11 | public class RemoveTests : TestBase 12 | { 13 | protected RedisOutputCache RedisApiOutputCache; 14 | IRedisConnectionSettings _connectionSettings; 15 | ConnectionMultiplexer _multiplexer; 16 | UserFixture _fixture; 17 | 18 | [TestFixtureSetUp] 19 | public void TestFixtureSetup() 20 | { 21 | _connectionSettings = new RedisConnectionSettings { ConnectionString = "localhost:6379", Db = 2 }; 22 | _multiplexer = ConnectionMultiplexer.Connect(_connectionSettings.ConnectionString); 23 | } 24 | 25 | protected override void FinalizeSetUp() 26 | { 27 | _fixture = FixtureRepository.Create(); 28 | 29 | RedisApiOutputCache = new RedisOutputCache(new JsonSerializer(), _connectionSettings); 30 | 31 | RedisApiOutputCache.Add(_fixture.Id.ToString(), _fixture, DateTime.Now.AddSeconds(60)); 32 | 33 | } 34 | 35 | private void ClearDb() 36 | { 37 | _multiplexer.GetServer(_connectionSettings.ConnectionString).FlushDatabase(_connectionSettings.Db); 38 | } 39 | 40 | 41 | [Test] 42 | public void removes_item_from_cache() 43 | { 44 | RedisApiOutputCache.Remove(_fixture.Id.ToString()); 45 | 46 | var result = RedisApiOutputCache.Get(_fixture.Id.ToString()); 47 | 48 | result.Should().BeNull(); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 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("WebAPI.OutputCache.Redis.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("WebAPI.OutputCache.Redis.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 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("822fd93e-7378-426e-9d38-af4ed63e7354")] 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")] 37 | -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis.Tests/UserFixture.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebAPI.OutputCache.Redis.Tests 4 | { 5 | public class UserFixture 6 | { 7 | public UserFixture() 8 | { 9 | Id = Guid.NewGuid(); 10 | } 11 | 12 | public Guid Id { get; set; } 13 | public string Name { get; set; } 14 | public DateTime DateOfBirth { get; set; } 15 | public DateTime ExpireAt { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis.Tests/WebAPI.OutputCache.Redis.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {822FD93E-7378-426E-9D38-AF4ED63E7354} 8 | Library 9 | Properties 10 | WebAPI.OutputCache.Redis.Tests 11 | WebAPI.OutputCache.Redis.Tests 12 | v4.5.1 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 6 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | ..\packages\Common.Testing.NUnit.1.0.0\lib\net45\Common.Testing.NUnit.dll 36 | True 37 | 38 | 39 | ..\packages\FluentAssertions.4.0.1\lib\net45\FluentAssertions.dll 40 | True 41 | 42 | 43 | ..\packages\FluentAssertions.4.0.1\lib\net45\FluentAssertions.Core.dll 44 | True 45 | 46 | 47 | ..\packages\Jil.2.12.1\lib\net45\Jil.dll 48 | True 49 | 50 | 51 | ..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll 52 | True 53 | 54 | 55 | ..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll 56 | True 57 | 58 | 59 | ..\packages\NUnit.2.6.4\lib\nunit.framework.dll 60 | True 61 | 62 | 63 | ..\packages\AutoFixture.3.36.11\lib\net40\Ploeh.AutoFixture.dll 64 | True 65 | 66 | 67 | ..\packages\Sigil.4.5.0\lib\net45\Sigil.dll 68 | True 69 | 70 | 71 | ..\packages\StackExchange.Redis.1.0.488\lib\net45\StackExchange.Redis.dll 72 | True 73 | 74 | 75 | 76 | 77 | ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll 78 | True 79 | 80 | 81 | 82 | 83 | ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll 84 | True 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | ..\packages\Strathweb.CacheOutput.WebApi2.0.9.0\lib\net45\WebApi.OutputCache.Core.dll 94 | True 95 | 96 | 97 | ..\packages\Strathweb.CacheOutput.WebApi2.0.9.0\lib\net45\WebApi.OutputCache.V2.dll 98 | True 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | {AA6D9D6A-2AB5-4BEF-980C-E14771C16E00} 117 | WebAPI.OutputCache.Redis 118 | 119 | 120 | 121 | 128 | -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis.Tests/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPI.OutputCache.Redis", "WebAPI.OutputCache.Redis\WebAPI.OutputCache.Redis.csproj", "{AA6D9D6A-2AB5-4BEF-980C-E14771C16E00}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPI.OutputCache.Redis.Tests", "WebAPI.OutputCache.Redis.Tests\WebAPI.OutputCache.Redis.Tests.csproj", "{822FD93E-7378-426E-9D38-AF4ED63E7354}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {AA6D9D6A-2AB5-4BEF-980C-E14771C16E00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {AA6D9D6A-2AB5-4BEF-980C-E14771C16E00}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {AA6D9D6A-2AB5-4BEF-980C-E14771C16E00}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {AA6D9D6A-2AB5-4BEF-980C-E14771C16E00}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {822FD93E-7378-426E-9D38-AF4ED63E7354}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {822FD93E-7378-426E-9D38-AF4ED63E7354}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {822FD93E-7378-426E-9D38-AF4ED63E7354}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {822FD93E-7378-426E-9D38-AF4ED63E7354}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis/IJsonSerializer.cs: -------------------------------------------------------------------------------- 1 | using Jil; 2 | 3 | namespace WebAPI.OutputCache.Redis 4 | { 5 | public interface IJsonSerializer 6 | { 7 | T DeserializeObject(string json, Options options= null); 8 | string SerializeObject(T value, Options options=null); 9 | } 10 | } -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis/IRedisConnectionSettings.cs: -------------------------------------------------------------------------------- 1 | namespace WebAPI.OutputCache.Redis 2 | { 3 | public interface IRedisConnectionSettings 4 | { 5 | int Db { get; set; } 6 | string ConnectionString { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis/JsonSerializer.cs: -------------------------------------------------------------------------------- 1 | using Jil; 2 | 3 | namespace WebAPI.OutputCache.Redis 4 | { 5 | /// 6 | /// Facade for . 7 | /// 8 | public class JsonSerializer : IJsonSerializer 9 | { 10 | public T DeserializeObject(string json, Options options = null) 11 | { 12 | return JSON.Deserialize(json,options); 13 | } 14 | 15 | public string SerializeObject(T value, Options options = null) 16 | { 17 | return JSON.Serialize(value, options); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 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("WebAPI.OutputCache.Redis")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("WebAPI.OutputCache.Redis")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 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("aa6d9d6a-2ab5-4bef-980c-e14771c16e00")] 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")] 37 | -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis/RedisConnectionSettings.cs: -------------------------------------------------------------------------------- 1 | namespace WebAPI.OutputCache.Redis 2 | { 3 | public class RedisConnectionSettings : IRedisConnectionSettings 4 | { 5 | public int Db { get; set; } 6 | public string ConnectionString { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis/RedisOutputCache.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Jil; 5 | using StackExchange.Redis; 6 | using WebApi.OutputCache.Core.Cache; 7 | 8 | namespace WebAPI.OutputCache.Redis 9 | { 10 | public class RedisOutputCache : IApiOutputCache 11 | { 12 | private readonly IJsonSerializer _jsonSerializer; 13 | private readonly IRedisConnectionSettings _connectionSettings; 14 | private readonly Lazy _multiplexer; 15 | readonly Options _options; 16 | 17 | public RedisOutputCache(IJsonSerializer jsonSerializer, IRedisConnectionSettings connectionSettings) 18 | { 19 | _jsonSerializer = jsonSerializer; 20 | _connectionSettings = connectionSettings; 21 | _multiplexer = new Lazy(() => ConnectionMultiplexer.Connect(_connectionSettings.ConnectionString)); 22 | 23 | _options = null;//TODO: 24 | } 25 | 26 | private IDatabase Db => _multiplexer.Value.GetDatabase(_connectionSettings.Db); 27 | 28 | public void RemoveStartsWith(string key) 29 | { 30 | //AutoInvalidateCacheOutputAttribute and InvalidateCacheOutputAttribute uses this method. 31 | //TODO: delete by pattern 32 | //EVAL "return redis.call('del', unpack(redis.call('keys', ARGV[1])))" 0 prefix:* 33 | //CAUTION : while deleting keys please use scan 34 | Db.KeyDelete(key); 35 | } 36 | 37 | public T Get(string key) where T : class 38 | { 39 | string redisValue = Db.StringGet(key); 40 | 41 | if (!string.IsNullOrEmpty(redisValue)) 42 | return _jsonSerializer.DeserializeObject(redisValue, _options); 43 | 44 | return null; 45 | } 46 | 47 | public object Get(string key) 48 | { 49 | return Db.StringGet(key); 50 | } 51 | 52 | public void Remove(string key) 53 | { 54 | Db.KeyDelete(key); 55 | } 56 | 57 | public bool Contains(string key) 58 | { 59 | return Db.KeyExists(key); 60 | } 61 | 62 | public void Add(string key, object o, DateTimeOffset expiration, string dependsOnKey = null) 63 | { 64 | TimeSpan timeSpan = expiration.DateTime.Subtract(DateTime.Now); 65 | Db.StringSet(key, _jsonSerializer.SerializeObject(o, _options), timeSpan); 66 | } 67 | 68 | //TODO: use SCAN to get keys 69 | public IEnumerable AllKeys => Enumerable.Empty(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis/WebAPI.OutputCache.Redis.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {AA6D9D6A-2AB5-4BEF-980C-E14771C16E00} 8 | Library 9 | Properties 10 | WebAPI.OutputCache.Redis 11 | WebAPI.OutputCache.Redis 12 | v4.5.1 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 6 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | ..\packages\Jil.2.12.1\lib\net45\Jil.dll 36 | True 37 | 38 | 39 | ..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll 40 | True 41 | 42 | 43 | ..\packages\Sigil.4.5.0\lib\net45\Sigil.dll 44 | True 45 | 46 | 47 | ..\packages\StackExchange.Redis.1.0.488\lib\net45\StackExchange.Redis.dll 48 | True 49 | 50 | 51 | 52 | 53 | ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll 54 | True 55 | 56 | 57 | 58 | 59 | ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll 60 | True 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | ..\packages\Strathweb.CacheOutput.WebApi2.0.9.0\lib\net45\WebApi.OutputCache.Core.dll 70 | True 71 | 72 | 73 | ..\packages\Strathweb.CacheOutput.WebApi2.0.9.0\lib\net45\WebApi.OutputCache.V2.dll 74 | True 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 97 | -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis/WebAPI.OutputCache.Redis.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | WebAPI.OutputCache.Redis 5 | WebAPI.OutputCache.Redis 6 | 1.0.0 7 | ziyasal 8 | ziyasal 9 | https://github.com/ziyasal/AspNetWebApi-OutputCache-Redis 10 | false 11 | https://github.com/ziyasal/AspNetWebApi-OutputCache-Redis/blob/master/LICENSE 12 | Redis cache for AspNetWebApi-OutputCache 13 | 14 | Redis provider for AspNetWebApi-OutputCache Implementation of IApiOutputCache for Redis 15 | 16 | redis aspnet webapi webapi2 cache output outputcache 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /WebAPI.OutputCache.Redis/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | configuration: Release 2 | branches: 3 | only: 4 | - master 5 | 6 | before_build: 7 | - nuget restore WebAPI.OutputCache.Redis.sln 8 | 9 | build: 10 | project: WebAPI.OutputCache.Redis.sln 11 | verbosity: minimal 12 | --------------------------------------------------------------------------------