diff --git a/.idea/.idea.DynaCache/.idea/.gitignore b/.idea/.idea.DynaCache/.idea/.gitignore
new file mode 100644
index 0000000..d6d136b
--- /dev/null
+++ b/.idea/.idea.DynaCache/.idea/.gitignore
@@ -0,0 +1,13 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Rider ignored files
+/projectSettingsUpdater.xml
+/.idea.DynaCache.iml
+/modules.xml
+/contentModel.xml
+# Datasource local storage ignored files
+/../../../../../../../../:\Source\Repositories\Personal\DynaCache\.idea\.idea.DynaCache\.idea/dataSources/
+/dataSources.local.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/.idea/.idea.DynaCache/.idea/encodings.xml b/.idea/.idea.DynaCache/.idea/encodings.xml
new file mode 100644
index 0000000..df87cf9
--- /dev/null
+++ b/.idea/.idea.DynaCache/.idea/encodings.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.DynaCache/.idea/indexLayout.xml b/.idea/.idea.DynaCache/.idea/indexLayout.xml
new file mode 100644
index 0000000..27ba142
--- /dev/null
+++ b/.idea/.idea.DynaCache/.idea/indexLayout.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.DynaCache/.idea/riderModule.iml b/.idea/.idea.DynaCache/.idea/riderModule.iml
new file mode 100644
index 0000000..1a4e0d9
--- /dev/null
+++ b/.idea/.idea.DynaCache/.idea/riderModule.iml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.DynaCache/.idea/vcs.xml b/.idea/.idea.DynaCache/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/.idea.DynaCache/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/DynaCache.AspNetCache/AspNetCacheService.cs b/DynaCache.AspNetCache/AspNetCacheService.cs
deleted file mode 100644
index 53fc0ea..0000000
--- a/DynaCache.AspNetCache/AspNetCacheService.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-#region Copyright 2012 Mike Goatly
-// This source is subject to the the MIT License (MIT)
-// All rights reserved.
-#endregion
-
-namespace DynaCache.AspNetCache
-{
- using System;
- using System.Web;
- using System.Web.Caching;
-
- ///
- /// An implementation of that uses the ASP.NET cache.
- ///
- public class AspNetCacheService : IDynaCacheService
- {
- ///
- /// Gets the ASP.NET cache associated to the HttpRuntime.
- ///
- public static Cache Cache
- {
- get
- {
- var cache = HttpRuntime.Cache;
- if (cache == null)
- {
- throw new InvalidOperationException("No cache available on the HttpRuntime.");
- }
-
- return cache;
- }
- }
-
- ///
- /// Tries to get a cached object from the cache using the given cache key.
- ///
- /// The cache key of the object to read from the cache.
- /// The object that was read from the cache, or null if the key
- /// could not be found in the cache.
- /// true if the item could be read from the cache, otherwise false.
- public virtual bool TryGetCachedObject(string cacheKey, out T result)
- {
- var sample = Cache[cacheKey];
- result = (sample is T)
- ? (T)sample
- : default(T);
- return result != null;
- }
-
- ///
- /// Stores an object in the cache.
- ///
- /// The cache key to store the object against.
- /// The data to store against the key.
- /// The duration, in seconds, to cache the data for.
- public virtual void SetCachedObject(string cacheKey, T data, int duration)
- {
- Cache.Insert(cacheKey, data, null, DateTime.Now.AddSeconds(duration), Cache.NoSlidingExpiration);
- }
- }
-}
diff --git a/DynaCache.AspNetCache/DynaCache.AspNetCache.csproj b/DynaCache.AspNetCache/DynaCache.AspNetCache.csproj
deleted file mode 100644
index efec36e..0000000
--- a/DynaCache.AspNetCache/DynaCache.AspNetCache.csproj
+++ /dev/null
@@ -1,71 +0,0 @@
-
-
-
- Debug
- AnyCPU
- 8.0.30703
- 2.0
- {A3C28BDA-FD00-41F6-973D-2F86E3BA8C7B}
- Library
- Properties
- DynaCache.AspNetCache
- DynaCache.AspNetCache
- v4.5.1
- 512
- SAK
- SAK
- SAK
- SAK
-
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
- Properties\CommonAssemblyInfo.cs
-
-
-
-
-
-
- {F4EE6A5E-A9EC-4119-A8E3-A1D270732D0D}
- DynaCache
-
-
-
-
-
\ No newline at end of file
diff --git a/DynaCache.AspNetCache/DynaCache.AspNetCache.csproj.vspscc b/DynaCache.AspNetCache/DynaCache.AspNetCache.csproj.vspscc
deleted file mode 100644
index b6d3289..0000000
--- a/DynaCache.AspNetCache/DynaCache.AspNetCache.csproj.vspscc
+++ /dev/null
@@ -1,10 +0,0 @@
-""
-{
-"FILE_VERSION" = "9237"
-"ENLISTMENT_CHOICE" = "NEVER"
-"PROJECT_FILE_RELATIVE_PATH" = ""
-"NUMBER_OF_EXCLUDED_FILES" = "0"
-"ORIGINAL_PROJECT_FILE_PATH" = ""
-"NUMBER_OF_NESTED_PROJECTS" = "0"
-"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
-}
diff --git a/DynaCache.AspNetCache/Properties/AssemblyInfo.cs b/DynaCache.AspNetCache/Properties/AssemblyInfo.cs
deleted file mode 100644
index 2678043..0000000
--- a/DynaCache.AspNetCache/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-#region Copyright 2012 Mike Goatly
-// This source is subject to the the MIT License (MIT)
-// All rights reserved.
-#endregion
-
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-[assembly: AssemblyTitle("DynaCache.AspNetCache")]
-[assembly: AssemblyDescription("A implementation of IDynaCacheService using the ASP.NET Cache")]
-[assembly: Guid("026bba54-a736-4912-9374-218b394aa223")]
diff --git a/DynaCache.Core.MemoryCache/DynaCache.Core.MemoryCache.csproj b/DynaCache.Core.MemoryCache/DynaCache.Core.MemoryCache.csproj
new file mode 100644
index 0000000..8521be4
--- /dev/null
+++ b/DynaCache.Core.MemoryCache/DynaCache.Core.MemoryCache.csproj
@@ -0,0 +1,18 @@
+
+
+
+ net5.0
+ DynaCache.MemoryCache
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DynaCache.Core.MemoryCache/Extensions/ServiceCollectionExtensions.cs b/DynaCache.Core.MemoryCache/Extensions/ServiceCollectionExtensions.cs
new file mode 100644
index 0000000..380ccbf
--- /dev/null
+++ b/DynaCache.Core.MemoryCache/Extensions/ServiceCollectionExtensions.cs
@@ -0,0 +1,13 @@
+using DynaCache.Services;
+using Microsoft.Extensions.DependencyInjection;
+
+namespace DynaCache.MemoryCache.Extensions
+{
+ public static class ServiceCollectionExtensions
+ {
+ public static void AddMemoryCacheService(this IServiceCollection services)
+ {
+ services.AddSingleton();
+ }
+ }
+}
\ No newline at end of file
diff --git a/DynaCache.MemoryCache/MemoryCacheService.cs b/DynaCache.Core.MemoryCache/MemoryCacheService.cs
similarity index 83%
rename from DynaCache.MemoryCache/MemoryCacheService.cs
rename to DynaCache.Core.MemoryCache/MemoryCacheService.cs
index e934dce..fb01992 100644
--- a/DynaCache.MemoryCache/MemoryCacheService.cs
+++ b/DynaCache.Core.MemoryCache/MemoryCacheService.cs
@@ -4,6 +4,10 @@
#endregion
using System;
+using System.Runtime.Caching;
+using System.Threading;
+using DynaCache.Services;
+using Microsoft.Extensions.Caching.Memory;
using MemCache = System.Runtime.Caching.MemoryCache;
namespace DynaCache.MemoryCache
@@ -21,7 +25,7 @@ public class MemoryCacheService : IDynaCacheService, IDisposable
///
/// The in-memory cache instance for this service.
///
- private readonly MemCache _cache = new MemCache("CacheService");
+ private MemCache _cache = new MemCache("CacheService");
///
/// Tries to get a cached object from the cache using the given cache key.
@@ -65,10 +69,25 @@ public virtual void SetCachedObject(string cacheKey, T data, int duration)
}
else
{
- _cache.Add(cacheKey, data, DateTime.Now.AddSeconds(duration));
+ var cacheItemPolicy = new CacheItemPolicy() //TODO to settings
+ {
+ SlidingExpiration = TimeSpan.FromSeconds(duration)
+ };
+
+ _cache.Set(cacheKey, data, cacheItemPolicy);
}
}
+ public void ClearCache()
+ {
+ var newCache = new MemCache("CacheService");
+ var oldCache = _cache;
+
+ _cache = newCache;
+
+ oldCache.Dispose();
+ }
+
///
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///
diff --git a/DynaCache.Core.TestApp/CustomConverters/CacheConverters.cs b/DynaCache.Core.TestApp/CustomConverters/CacheConverters.cs
new file mode 100644
index 0000000..359b808
--- /dev/null
+++ b/DynaCache.Core.TestApp/CustomConverters/CacheConverters.cs
@@ -0,0 +1,17 @@
+using System.Collections.Generic;
+
+namespace DynaCache.TestApp.CustomConverters
+{
+ public static class CacheConverters
+ {
+ public static string TestConvert(Test test)
+ {
+ return test.Kekos.ToString();
+ }
+
+ public static string ListConvert(List list)
+ {
+ return string.Join(",", list);
+ }
+ }
+}
\ No newline at end of file
diff --git a/DynaCache.Core.TestApp/DynaCache.Core.TestApp.csproj b/DynaCache.Core.TestApp/DynaCache.Core.TestApp.csproj
new file mode 100644
index 0000000..8b5d9a7
--- /dev/null
+++ b/DynaCache.Core.TestApp/DynaCache.Core.TestApp.csproj
@@ -0,0 +1,17 @@
+
+
+
+ Exe
+ net5.0
+ DynaCache.TestApp
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DynaCache.TestApp/IRandomService.cs b/DynaCache.Core.TestApp/IRandomService.cs
similarity index 87%
rename from DynaCache.TestApp/IRandomService.cs
rename to DynaCache.Core.TestApp/IRandomService.cs
index f39312a..2461d9b 100644
--- a/DynaCache.TestApp/IRandomService.cs
+++ b/DynaCache.Core.TestApp/IRandomService.cs
@@ -3,6 +3,8 @@
// All rights reserved.
#endregion
+using System.Collections.Generic;
+
namespace DynaCache.TestApp
{
///
@@ -16,6 +18,6 @@ public interface IRandomService
/// The minimum value to return (inclusive).
/// The maximum value to return (exclusive).
/// The random number.
- int GetRandomNumber(int minInclusive, int maxExclusive);
+ int GetRandomNumber(List minInclusive);
}
}
diff --git a/DynaCache.Core.TestApp/Program.cs b/DynaCache.Core.TestApp/Program.cs
new file mode 100644
index 0000000..48918d3
--- /dev/null
+++ b/DynaCache.Core.TestApp/Program.cs
@@ -0,0 +1,61 @@
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using DynaCache.Extensions;
+using DynaCache.MemoryCache.Extensions;
+using DynaCache.Services;
+using DynaCache.TestApp.CustomConverters;
+using Microsoft.Extensions.DependencyInjection;
+
+namespace DynaCache.TestApp
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ Cacheable.AddCustomConverter(CacheConverters.TestConvert);
+ Cacheable.AddCustomConverter>(CacheConverters.ListConvert);
+ var services = new ServiceCollection();
+
+ services.AddMemoryCacheService();
+ services.AddCacheable();
+
+ services.AddTransient();
+
+ var serviceProvider = services.BuildServiceProvider();
+
+ var service = serviceProvider.GetRequiredService();
+
+ var cacheService = serviceProvider.GetRequiredService();
+
+ Task.Run(() =>
+ {
+ while (true)
+ {
+ Console.ReadKey();
+ cacheService.ClearCache();
+ }
+ });
+
+ while (true)
+ {
+ var test = new Test()
+ {
+ Kekos = 1
+ };
+
+ var list = new List
+ {
+ 1
+ };
+
+ // The result from the GetRandomNumber method on the service has its results cached for 1 second
+ // therefore the displayed results should only change every 4th iteration.
+ Console.WriteLine("Random number between 1 and 10: {0}", service.GetRandomNumber(list));
+
+ Thread.Sleep(250);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/DynaCache.TestApp/RandomService.cs b/DynaCache.Core.TestApp/RandomService.cs
similarity index 65%
rename from DynaCache.TestApp/RandomService.cs
rename to DynaCache.Core.TestApp/RandomService.cs
index bf0dece..eed2985 100644
--- a/DynaCache.TestApp/RandomService.cs
+++ b/DynaCache.Core.TestApp/RandomService.cs
@@ -3,6 +3,10 @@
// All rights reserved.
#endregion
+using System.Collections.Generic;
+using System.Linq;
+using DynaCache.Attributes;
+
namespace DynaCache.TestApp
{
using System;
@@ -12,10 +16,12 @@ namespace DynaCache.TestApp
///
public class RandomService : IRandomService
{
- ///
- /// The random instance to use when generating random numbers.
- ///
- private readonly Random _random = new Random();
+ private readonly Random _random;
+
+ public RandomService(Random random)
+ {
+ _random = random;
+ }
///
/// Gets a random number between the given bounds.
@@ -25,10 +31,10 @@ public class RandomService : IRandomService
///
/// The random number.
///
- [CacheableMethod(1)]
- public virtual int GetRandomNumber(int minInclusive, int maxExclusive)
+ [CacheableMethod(10000)]
+ public virtual int GetRandomNumber(List minInclusive)
{
- return _random.Next(minInclusive, maxExclusive);
+ return _random.Next(minInclusive.First(), 20);
}
}
}
diff --git a/DynaCache.Core.TestApp/Test.cs b/DynaCache.Core.TestApp/Test.cs
new file mode 100644
index 0000000..e043469
--- /dev/null
+++ b/DynaCache.Core.TestApp/Test.cs
@@ -0,0 +1,7 @@
+namespace DynaCache.TestApp
+{
+ public class Test
+ {
+ public int Kekos { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/DynaCache/CacheableMethodAttribute.cs b/DynaCache.Core/Attributes/CacheableMethodAttribute.cs
similarity index 55%
rename from DynaCache/CacheableMethodAttribute.cs
rename to DynaCache.Core/Attributes/CacheableMethodAttribute.cs
index a0211d7..97e6029 100644
--- a/DynaCache/CacheableMethodAttribute.cs
+++ b/DynaCache.Core/Attributes/CacheableMethodAttribute.cs
@@ -3,11 +3,10 @@
// All rights reserved.
#endregion
-namespace DynaCache
-{
- using System;
- using System.Configuration;
+using System;
+namespace DynaCache.Attributes
+{
///
/// An attribute that can be applied to a method, causing the results of the method to be cached, varying by the parameter
/// values being passed into it.
@@ -15,21 +14,6 @@ namespace DynaCache
[AttributeUsage(AttributeTargets.Method)]
public sealed class CacheableMethodAttribute : Attribute
{
- ///
- /// There's a better way to do this, i.e. configuration reading needs to take place outside the attribute;
- /// in Azure, for example, this should be CloudConfigurationManager. For now, we aren't supporting that, so this will suffice.
- ///
- private static readonly DynaCacheSection Configuration = ConfigurationManager.GetSection("dynaCache") as DynaCacheSection;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The name of the cache duration to look up in the configuration file.
- public CacheableMethodAttribute(string namedCacheDuration)
- {
- CacheSeconds = (int)Configuration.CacheDurations[namedCacheDuration].Duration.TotalSeconds;
- }
-
///
/// Initializes a new instance of the class.
///
@@ -51,10 +35,6 @@ public CacheableMethodAttribute(TimeSpan duration)
///
/// Gets the number of seconds to cache the results for.
///
- public int CacheSeconds
- {
- get;
- private set;
- }
+ public int CacheSeconds { get; }
}
}
diff --git a/DynaCache/ToStringableAttribute.cs b/DynaCache.Core/Attributes/ToStringableAttribute.cs
similarity index 90%
rename from DynaCache/ToStringableAttribute.cs
rename to DynaCache.Core/Attributes/ToStringableAttribute.cs
index 83996b7..992ab5c 100644
--- a/DynaCache/ToStringableAttribute.cs
+++ b/DynaCache.Core/Attributes/ToStringableAttribute.cs
@@ -3,10 +3,10 @@
// All rights reserved.
#endregion
-namespace DynaCache
-{
- using System;
+using System;
+namespace DynaCache.Attributes
+{
///
/// An attribute that can be applied to a class, causing DynaCache to assume thatthis class implementation of ToString()
/// returns unique keys
diff --git a/DynaCache.Core/DynaCache.Core.csproj b/DynaCache.Core/DynaCache.Core.csproj
new file mode 100644
index 0000000..b19404b
--- /dev/null
+++ b/DynaCache.Core/DynaCache.Core.csproj
@@ -0,0 +1,12 @@
+
+
+
+ net5.0
+ DynaCache
+
+
+
+
+
+
+
diff --git a/DynaCache/DynaCacheException.cs b/DynaCache.Core/Exceptions/DynaCacheException.cs
similarity index 95%
rename from DynaCache/DynaCacheException.cs
rename to DynaCache.Core/Exceptions/DynaCacheException.cs
index c4fb73d..9d2883e 100644
--- a/DynaCache/DynaCacheException.cs
+++ b/DynaCache.Core/Exceptions/DynaCacheException.cs
@@ -3,11 +3,11 @@
// All rights reserved.
#endregion
-namespace DynaCache
-{
- using System;
- using System.Runtime.Serialization;
+using System;
+using System.Runtime.Serialization;
+namespace DynaCache.Exceptions
+{
///
/// Represents an error that occurs during DynaCache cacheable type generation.
///
diff --git a/DynaCache.Core/Extensions/ServiceCollectionExtensions.cs b/DynaCache.Core/Extensions/ServiceCollectionExtensions.cs
new file mode 100644
index 0000000..1ec28d5
--- /dev/null
+++ b/DynaCache.Core/Extensions/ServiceCollectionExtensions.cs
@@ -0,0 +1,30 @@
+using Microsoft.Extensions.DependencyInjection;
+
+namespace DynaCache.Extensions
+{
+ public static class ServiceCollectionExtensions
+ {
+ public static void AddCacheable(this IServiceCollection services, ServiceLifetime serviceLifetime = ServiceLifetime.Singleton)
+ where T : class
+ {
+ services.AddCacheable(serviceLifetime);
+ }
+
+ public static void AddCacheable(this IServiceCollection services, ServiceLifetime serviceLifetime = ServiceLifetime.Singleton)
+ where TTo : class
+ {
+ switch (serviceLifetime)
+ {
+ case ServiceLifetime.Singleton:
+ services.AddSingleton(typeof(TFrom), Cacheable.CreateType());
+ break;
+ case ServiceLifetime.Transient:
+ services.AddTransient(typeof(TFrom), Cacheable.CreateType());
+ break;
+ case ServiceLifetime.Scoped:
+ services.AddScoped(typeof(TFrom), Cacheable.CreateType());
+ break;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/DynaCache/Cacheable.cs b/DynaCache.Core/Services/Cacheable.cs
similarity index 92%
rename from DynaCache/Cacheable.cs
rename to DynaCache.Core/Services/Cacheable.cs
index 803027a..100a683 100644
--- a/DynaCache/Cacheable.cs
+++ b/DynaCache.Core/Services/Cacheable.cs
@@ -3,18 +3,19 @@
// All rights reserved.
#endregion
-using System.Runtime.InteropServices;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Runtime.CompilerServices;
+using System.Text;
+using DynaCache.Attributes;
+using DynaCache.Exceptions;
+using DynaCache.Services;
namespace DynaCache
{
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Reflection;
- using System.Reflection.Emit;
- using System.Runtime.CompilerServices;
- using System.Text;
///
/// Cacheable provides the ability to create a dynamic cache proxy type for a class.
///
@@ -64,38 +65,16 @@ public static class Cacheable
///
private static readonly AssemblyName AssemblyName = new AssemblyName("Dynamic Cacheable Proxies");
-#if DEBUG
- ///
- /// The dynamic assembly build that will be used to define the cacheable types.
- ///
- private static readonly AssemblyBuilder AssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess.RunAndSave);
- ///
- /// The dynamic module that the cacheable types will be created in.
- ///
- private static readonly ModuleBuilder Module = AssemblyBuilder.DefineDynamicModule(AssemblyName.Name, "test.dll");
-#else
///
/// The dynamic assembly build that will be used to define the cacheable types.
///
- private static readonly AssemblyBuilder AssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess.Run);
+ private static readonly AssemblyBuilder AssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess.Run);
///
/// The dynamic module that the cacheable types will be created in.
///
private static readonly ModuleBuilder Module = AssemblyBuilder.DefineDynamicModule(AssemblyName.Name);
-#endif
-
-#if DEBUG
- ///
- /// Saves the underlying assembly.
- ///
- [Conditional("DEBUG")]
- public static void SaveAssembly()
- {
- AssemblyBuilder.Save("test.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.I386);
- }
-#endif
///
/// Creates a dynamic cache proxy type for a given type. Any methods that are decorated with
@@ -260,22 +239,21 @@ private static void DefineConstructor(Type type, Type[] constructorSignature, Ty
private static ConstructorInfo ChooseConstructor(Type type, ConstructorInfo[] constructors, Type[] constructorSignature)
{
ConstructorInfo result;
- /*
- if (constructors.Length > 1)
+
+ if ((constructorSignature == null || constructorSignature.Length == 0) && constructors.Length > 1)
{
- throw new DynaCacheException("Only one constructor is supported at the moment - sorry.");
+ throw new DynaCacheException("Only one constructor is supported without constructorSignature");
}
- */
if (constructorSignature == null || constructorSignature.Length == 0)
{
- result = constructors.Where(v => v.GetParameters().Length == 0).FirstOrDefault();
+ result = constructors.FirstOrDefault();
if (result == null)
{
throw new DynaCacheException(
- string.Format("Required constructor w/o parameters is missing. Correct \"constructorSignature\" or constructor in type <{0}>.", type.Name)
- );
+ $"Required constructor w/o parameters is missing. Correct \"constructorSignature\" or constructor in type <{type.Name}>."
+ );
}
}
else
diff --git a/DynaCache/IDynaCacheService.cs b/DynaCache.Core/Services/IDynaCacheService.cs
similarity index 92%
rename from DynaCache/IDynaCacheService.cs
rename to DynaCache.Core/Services/IDynaCacheService.cs
index 04558ac..30ce68c 100644
--- a/DynaCache/IDynaCacheService.cs
+++ b/DynaCache.Core/Services/IDynaCacheService.cs
@@ -3,7 +3,7 @@
// All rights reserved.
#endregion
-namespace DynaCache
+namespace DynaCache.Services
{
///
/// The interface implemented by classes capable of acting as a backing cache that
@@ -28,5 +28,10 @@ public interface IDynaCacheService
/// The data to store against the key.
/// The duration, in seconds, to cache the data for.
void SetCachedObject(string cacheKey, T data, int duration);
+
+ ///
+ /// Clear all data from cache
+ ///
+ void ClearCache();
}
}
diff --git a/DynaCache.MemoryCache/DynaCache.MemoryCache.csproj b/DynaCache.MemoryCache/DynaCache.MemoryCache.csproj
deleted file mode 100644
index d231bb6..0000000
--- a/DynaCache.MemoryCache/DynaCache.MemoryCache.csproj
+++ /dev/null
@@ -1,82 +0,0 @@
-
-
-
- Debug
- AnyCPU
- 8.0.30703
- 2.0
- {37A75E49-01D3-4AC5-BAB9-CE31EA518859}
- Library
- Properties
- DynaCache.MemoryCache
- DynaCache.MemoryCache
- v4.5
- 512
- SAK
- SAK
- SAK
- SAK
-
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
- bin\Release\DynaCache.MemoryCache.XML
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Properties\CommonAssemblyInfo.cs
-
-
-
-
-
-
- {f4ee6a5e-a9ec-4119-a8e3-a1d270732d0d}
- DynaCache
-
-
-
-
- $(OutputPath)\..\..\..\Nuget\
- $(NugetFolder)PackageContents\lib\
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/DynaCache.MemoryCache/DynaCache.MemoryCache.csproj.vspscc b/DynaCache.MemoryCache/DynaCache.MemoryCache.csproj.vspscc
deleted file mode 100644
index b6d3289..0000000
--- a/DynaCache.MemoryCache/DynaCache.MemoryCache.csproj.vspscc
+++ /dev/null
@@ -1,10 +0,0 @@
-""
-{
-"FILE_VERSION" = "9237"
-"ENLISTMENT_CHOICE" = "NEVER"
-"PROJECT_FILE_RELATIVE_PATH" = ""
-"NUMBER_OF_EXCLUDED_FILES" = "0"
-"ORIGINAL_PROJECT_FILE_PATH" = ""
-"NUMBER_OF_NESTED_PROJECTS" = "0"
-"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
-}
diff --git a/DynaCache.MemoryCache/Properties/AssemblyInfo.cs b/DynaCache.MemoryCache/Properties/AssemblyInfo.cs
deleted file mode 100644
index 2d64b3b..0000000
--- a/DynaCache.MemoryCache/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-#region Copyright 2012 Mike Goatly
-// This source is subject to the the MIT License (MIT)
-// All rights reserved.
-#endregion
-
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-[assembly: AssemblyTitle("DynaCache.MemoryCache")]
-[assembly: AssemblyDescription("A implementation of IDynaCacheService using the .NET 4.0 MemoryCache.")]
-[assembly: Guid("64c46c3a-af08-4e24-a107-484ad320e09f")]
diff --git a/DynaCache.MultilevelCache/Configuration/CacheConfigurationProviderService.cs b/DynaCache.MultilevelCache/Configuration/CacheConfigurationProviderService.cs
deleted file mode 100644
index 9151414..0000000
--- a/DynaCache.MultilevelCache/Configuration/CacheConfigurationProviderService.cs
+++ /dev/null
@@ -1,86 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Configuration;
-using System.Linq;
-using System.Text;
-using DynaCache.MultilevelCache.Configuration.CacheDispatcher;
-using DynaCache.MultilevelCache.Domain;
-using DynaCache.MultilevelCache.Internals;
-using Functional.Maybe;
-using Ninject;
-using NLog;
-using NLog.Extension;
-
-namespace DynaCache.MultilevelCache.Configuration
-{
- internal class CacheConfigurationProviderService : ICacheConfigurationProviderService
- {
- private const string CacheDispatcherSectionName = "cacheDispatcher";
-
- private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
- private readonly CacheDispatcherConfiguration _cdSection;
-
- private readonly IDynaCacheService[] _leveledCacheServiceImplementations;
-
- public CacheConfigurationProviderService([Named("SlaveCache")] IDynaCacheService[] leveledCacheServiceImplementations)
- {
- _cdSection = (CacheDispatcherConfiguration)ConfigurationManager.GetSection(CacheDispatcherSectionName);
- _leveledCacheServiceImplementations = leveledCacheServiceImplementations;
- }
-
- public uint GetCurrentCacheVersion()
- => ParseCacheVersion(_cdSection.CurrentCacheVersion, nameof(_cdSection.CurrentCacheVersion));
-
- public uint GetPreviousCacheVersion()
- => ParseCacheVersion(_cdSection.PreviousCacheVersion, nameof(_cdSection.PreviousCacheVersion));
-
- public IReadOnlyCollection GetCachingServices()
- {
- return _cdSection.CachingServices
- .Cast()
- .Select(ParseCachingService)
- .WhereValueExist()
- .ToList();
- }
-
- private Maybe ParseCachingService(CachingService raw)
- {
- using (new TracingLogProxy(logger))
- {
- var errors = new StringBuilder();
- var instance = _leveledCacheServiceImplementations
- .Where(i => i.GetType().FullName == raw.Type)
- .FirstMaybe();
- if (!instance.HasValue)
- errors.AppendLine($"cannot find type with name {raw.Type} among implemented {nameof(IDynaCacheService)}");
- var lifeSpan = raw.Expiration.ParseMaybe(long.TryParse);
- if (!lifeSpan.HasValue)
- errors.AppendLine($"failed to parse {nameof(raw.Expiration)} value {raw.Expiration}");
- var timeout = raw.Timeout.ParseMaybe(long.TryParse);
- if (!timeout.HasValue)
- errors.AppendLine($"failed to parse {nameof(raw.Timeout)} value {raw.Timeout}");
- if (errors.Length == 0)
- return new CacheServiceContext
- {
- Name = raw.Name,
- ServiceInstance = instance.Value,
- RetrievalTimeout = TimeSpan.FromMilliseconds(timeout.Value),
- CacheLifeSpan = TimeSpan.FromMilliseconds(lifeSpan.Value)
- }.ToMaybe();
- logger.Error($"failed to parse {raw.Name} configuration entry due to following errors:{Environment.NewLine}{errors}");
- return Maybe.Nothing;
- }
- }
-
- private static uint ParseCacheVersion(string entryValue, string entryName)
- {
- using (new TracingLogProxy(logger))
- {
- uint res;
- if (!uint.TryParse(entryValue, out res))
- logger.Error($"failed to parse {entryName} value {entryValue} as uint");
- return res;
- }
- }
- }
-}
\ No newline at end of file
diff --git a/DynaCache.MultilevelCache/Configuration/CacheDispatcher/CacheDispatcherConfiguration.cs b/DynaCache.MultilevelCache/Configuration/CacheDispatcher/CacheDispatcherConfiguration.cs
deleted file mode 100644
index 6bba5c0..0000000
--- a/DynaCache.MultilevelCache/Configuration/CacheDispatcher/CacheDispatcherConfiguration.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System.Configuration;
-
-namespace DynaCache.MultilevelCache.Configuration.CacheDispatcher
-{
- public class CacheDispatcherConfiguration : ConfigurationSection
- {
- private const string CachingServicesNodeName = "cachingServices";
- private const string CurrentCacheVersionNodeName = "currentCacheVersion";
- private const string PreviousCacheVersionNodeName = "previousCacheVersion";
-
- [ConfigurationProperty(CachingServicesNodeName)]
- public CachingServices CachingServices => (CachingServices)base[CachingServicesNodeName];
-
- [ConfigurationProperty(CurrentCacheVersionNodeName, IsRequired = true, IsKey = false)]
- public string CurrentCacheVersion => (string)base[CurrentCacheVersionNodeName];
-
- [ConfigurationProperty(PreviousCacheVersionNodeName, IsRequired = true, IsKey = false)]
- public string PreviousCacheVersion => (string)base[PreviousCacheVersionNodeName];
- }
-}
\ No newline at end of file
diff --git a/DynaCache.MultilevelCache/Configuration/CacheDispatcher/CachingService.cs b/DynaCache.MultilevelCache/Configuration/CacheDispatcher/CachingService.cs
deleted file mode 100644
index 05155f8..0000000
--- a/DynaCache.MultilevelCache/Configuration/CacheDispatcher/CachingService.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using System.Configuration;
-
-namespace DynaCache.MultilevelCache.Configuration.CacheDispatcher
-{
- public class CachingService : ConfigurationElement
- {
- internal const string CachingServiceNodeName = "cachingService";
- private const string NameNodeName = "name";
- private const string TypeNodeName = "type";
- private const string TimeoutNodeName = "timeout";
- private const string ExpirationNodeName = "expiration";
-
- [ConfigurationProperty(NameNodeName, IsKey = false, IsRequired = true)]
- public string Name => (string)base[NameNodeName];
-
- [ConfigurationProperty(TypeNodeName, IsKey = true, IsRequired = true)]
- public string Type => (string)base[TypeNodeName];
-
- [ConfigurationProperty(TimeoutNodeName, IsKey = false, IsRequired = true)]
- public string Timeout => (string)base[TimeoutNodeName];
-
- [ConfigurationProperty(ExpirationNodeName, IsKey = false, IsRequired = true)]
- public string Expiration => (string)base[ExpirationNodeName];
-
- public override string ToString()
- {
- return
- $"{{{nameof(Name)} = {Name}, {nameof(Type)} = {Type}, {nameof(Timeout)} = {Timeout}, {nameof(Expiration)} = {Expiration}}}";
- }
- }
-}
\ No newline at end of file
diff --git a/DynaCache.MultilevelCache/Configuration/CacheDispatcher/CachingServices.cs b/DynaCache.MultilevelCache/Configuration/CacheDispatcher/CachingServices.cs
deleted file mode 100644
index ab253b0..0000000
--- a/DynaCache.MultilevelCache/Configuration/CacheDispatcher/CachingServices.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using System.Configuration;
-
-namespace DynaCache.MultilevelCache.Configuration.CacheDispatcher
-{
- [ConfigurationCollection(typeof(CachingService), AddItemName = CachingService.CachingServiceNodeName)]
- public class CachingServices : ConfigurationElementCollection
- {
- protected override ConfigurationElement CreateNewElement()
- {
- return new CachingService();
- }
-
- protected override object GetElementKey(ConfigurationElement element)
- {
- return ((CachingService)element).Name;
- }
- }
-}
\ No newline at end of file
diff --git a/DynaCache.MultilevelCache/Configuration/ICacheConfigurationProviderService.cs b/DynaCache.MultilevelCache/Configuration/ICacheConfigurationProviderService.cs
deleted file mode 100644
index 2e60a41..0000000
--- a/DynaCache.MultilevelCache/Configuration/ICacheConfigurationProviderService.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using System.Collections.Generic;
-using DynaCache.MultilevelCache.Domain;
-
-namespace DynaCache.MultilevelCache.Configuration
-{
- public interface ICacheConfigurationProviderService
- {
- uint GetCurrentCacheVersion();
- uint GetPreviousCacheVersion();
- IReadOnlyCollection GetCachingServices();
- }
-}
\ No newline at end of file
diff --git a/DynaCache.MultilevelCache/Domain/CacheServiceContext.cs b/DynaCache.MultilevelCache/Domain/CacheServiceContext.cs
deleted file mode 100644
index d501a88..0000000
--- a/DynaCache.MultilevelCache/Domain/CacheServiceContext.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using System;
-
-namespace DynaCache.MultilevelCache.Domain
-{
- public class CacheServiceContext
- {
- public string Name { get; set; }
- public IDynaCacheService ServiceInstance { get; set; }
- public TimeSpan RetrievalTimeout { get; set; }
- public TimeSpan CacheLifeSpan { get; set; }
- }
-}
\ No newline at end of file
diff --git a/DynaCache.MultilevelCache/DynaCache.MultilevelCache.csproj b/DynaCache.MultilevelCache/DynaCache.MultilevelCache.csproj
deleted file mode 100644
index e5a1845..0000000
--- a/DynaCache.MultilevelCache/DynaCache.MultilevelCache.csproj
+++ /dev/null
@@ -1,98 +0,0 @@
-
-
-
-
- Debug
- AnyCPU
- {F603301D-977A-4BA2-8B09-70F2B645A12E}
- Library
- Properties
- DynaCache.MultilevelCache
- DynaCache.MultilevelCache
- v4.5.1
- 512
-
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
- ..\packages\Functional.Maybe.1.1.0\lib\portable40-net40+win8\Functional.Maybe.dll
- True
-
-
- ..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll
- True
-
-
- ..\packages\NLog.4.3.1\lib\net45\NLog.dll
- True
-
-
- ..\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll
- True
-
-
- ..\packages\StackExchange.Redis.1.0.488\lib\net45\StackExchange.Redis.dll
- True
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {F4EE6A5E-A9EC-4119-A8E3-A1D270732D0D}
- DynaCache
-
-
- {3ABC04DB-454F-4543-99E3-84BF6875DA95}
- NLog.Extension
-
-
-
-
-
\ No newline at end of file
diff --git a/DynaCache.MultilevelCache/Internals/Extensions.cs b/DynaCache.MultilevelCache/Internals/Extensions.cs
deleted file mode 100644
index 6984a4c..0000000
--- a/DynaCache.MultilevelCache/Internals/Extensions.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using Functional.Maybe;
-
-namespace DynaCache.MultilevelCache.Internals
-{
- internal static class StringExtensions
- {
- public static Maybe ParseMaybe(this string that, ParseDelegate parser)
- {
- T res;
- return parser(that, out res)
- ? res.ToMaybe()
- : Maybe.Nothing;
- }
-
- internal delegate bool ParseDelegate(string val, out T res);
- }
-}
\ No newline at end of file
diff --git a/DynaCache.MultilevelCache/MultilevelCacheModule.cs b/DynaCache.MultilevelCache/MultilevelCacheModule.cs
deleted file mode 100644
index 0262113..0000000
--- a/DynaCache.MultilevelCache/MultilevelCacheModule.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using DynaCache.MultilevelCache.Configuration;
-using Ninject.Modules;
-
-namespace DynaCache.MultilevelCache
-{
- public class MultilevelCacheModule : NinjectModule
- {
- public override void Load()
- {
- Bind().To();
- }
- }
-}
diff --git a/DynaCache.MultilevelCache/MultilevelCacheService.cs b/DynaCache.MultilevelCache/MultilevelCacheService.cs
deleted file mode 100644
index 3230bbb..0000000
--- a/DynaCache.MultilevelCache/MultilevelCacheService.cs
+++ /dev/null
@@ -1,124 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text.RegularExpressions;
-using System.Threading;
-using System.Threading.Tasks;
-using DynaCache.MultilevelCache.Configuration;
-using DynaCache.MultilevelCache.Domain;
-using DynaCache.MultilevelCache.Internals;
-using Functional.Maybe;
-using NLog;
-using NLog.Extension;
-
-namespace DynaCache.MultilevelCache
-{
- public class MultilevelCacheService : IDynaCacheService
- {
- private const string CacheVersionPrefix = "cache-version:";
-
- private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
-
- private readonly IReadOnlyCollection _cacheServices;
- private readonly uint _currentCacheVersion;
- private readonly uint _previousCacheVersion;
-
- public MultilevelCacheService(ICacheConfigurationProviderService configurationProviderService)
- {
- _cacheServices = configurationProviderService.GetCachingServices();
- _currentCacheVersion = configurationProviderService.GetCurrentCacheVersion();
- _previousCacheVersion = configurationProviderService.GetPreviousCacheVersion();
- }
-
-
- public bool TryGetCachedObject(string cacheKey, out T result)
- {
- var retrieved = RetrieveMaybe(cacheKey, _currentCacheVersion) // try to get value from current cache version
- .Or(() =>
- {
- var res = RetrieveMaybe(cacheKey, _previousCacheVersion); // try to get value from previous cache version
- res.Do(v => Store(cacheKey, _currentCacheVersion, v)); // save to new version if old version fits new
- return res;
- });
- result = retrieved.Value;
- return retrieved.HasValue;
- }
-
- public void SetCachedObject(string cacheKey, T data, int duration)
- => Store(cacheKey, _currentCacheVersion, data, TimeSpan.FromSeconds(duration));
-
- private Maybe RetrieveMaybe(string cacheKey, uint cacheVersion)
- {
- using (new TracingLogProxy(logger))
- {
- var emptyCacheServices = new List();
- var versionedCacheKey = ApplyVersionToKey(cacheKey, cacheVersion);
- logger.Debug($"requested value for {versionedCacheKey} key");
- foreach (var cacheServiceContext in _cacheServices)
- {
- var cts = new CancellationTokenSource();
- var pending = Task.Run(() => versionedCacheKey.ParseMaybe(cacheServiceContext.ServiceInstance.TryGetCachedObject), cts.Token);
- try
- {
- var timedOut = !pending.Wait(cacheServiceContext.RetrievalTimeout);
- if (timedOut)
- {
- cts.Cancel();
- logger.Warn($"cache request for {versionedCacheKey} at {cacheServiceContext.Name} has timed out");
- emptyCacheServices.Add(cacheServiceContext);
- continue;
- }
- }
- catch (Exception e)
- {
- logger.Error(e, $"cache request for {versionedCacheKey} at {cacheServiceContext.Name} has faulted");
- emptyCacheServices.Add(cacheServiceContext);
- continue;
- }
- var res = pending.Result;
- if (res.HasValue)
- {
- emptyCacheServices.ForEach(ecs => ecs.ServiceInstance.SetCachedObject(versionedCacheKey, res.Value, ecs.CacheLifeSpan.Seconds));
- return res;
- }
- logger.Debug($"cache not found for {versionedCacheKey} at {cacheServiceContext.Name}");
- emptyCacheServices.Add(cacheServiceContext);
- }
- logger.Debug($"failed to find cached value for {versionedCacheKey}");
- return Maybe.Nothing;
- }
- }
-
- private void Store(string cacheKey, uint cacheVersion, T value, TimeSpan? lastServiceExpiration = null)
- {
- using (new TracingLogProxy(logger))
- {
- var versionedCacheKey = ApplyVersionToKey(cacheKey, cacheVersion);
- logger.Debug($"storing value for key {versionedCacheKey} in cache");
- Task.Run(() =>
- {
- using (var iteration = _cacheServices.GetEnumerator())
- {
- if (!iteration.MoveNext())
- return;
- var cs = iteration.Current;
- while (iteration.MoveNext())
- {
- cs.ServiceInstance.SetCachedObject(versionedCacheKey, value, cs.CacheLifeSpan.Seconds);
- cs = iteration.Current;
- }
- cs.ServiceInstance.SetCachedObject(versionedCacheKey, value,
- lastServiceExpiration?.Seconds ?? cs.CacheLifeSpan.Seconds);
- }
- });
- }
- }
-
- private static string ApplyVersionToKey(string cacheKey, uint cacheVersion)
- {
- using (new TracingLogProxy(logger))
- return Regex.IsMatch(cacheKey, $@"{Regex.Escape(CacheVersionPrefix)}\d+$")
- ? cacheKey
- : $"{CacheVersionPrefix}{cacheVersion}:" + cacheKey;
- }
- }
-}
\ No newline at end of file
diff --git a/DynaCache.MultilevelCache/Properties/AssemblyInfo.cs b/DynaCache.MultilevelCache/Properties/AssemblyInfo.cs
deleted file mode 100644
index 6d72ef2..0000000
--- a/DynaCache.MultilevelCache/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-
-[assembly: AssemblyTitle("DynaCache.MultilevelCache")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("DynaCache.MultilevelCache")]
-[assembly: AssemblyCopyright("Copyright © 2016")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-
-[assembly: Guid("f603301d-977a-4ba2-8b09-70f2b645a12e")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
\ No newline at end of file
diff --git a/DynaCache.MultilevelCache/packages.config b/DynaCache.MultilevelCache/packages.config
deleted file mode 100644
index 6e61dcc..0000000
--- a/DynaCache.MultilevelCache/packages.config
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/DynaCache.RedisCache/Configuration/IRedisConfigurationProviderService.cs b/DynaCache.RedisCache/Configuration/IRedisConfigurationProviderService.cs
deleted file mode 100644
index 4f09b2f..0000000
--- a/DynaCache.RedisCache/Configuration/IRedisConfigurationProviderService.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using StackExchange.Redis;
-
-namespace DynaCache.RedisCache.Configuration
-{
- public interface IRedisConfigurationProviderService
- {
- ConfigurationOptions GetMultiplexorOptions();
- }
-}
\ No newline at end of file
diff --git a/DynaCache.RedisCache/Configuration/Redis/Endpoint.cs b/DynaCache.RedisCache/Configuration/Redis/Endpoint.cs
deleted file mode 100644
index 83d7d2b..0000000
--- a/DynaCache.RedisCache/Configuration/Redis/Endpoint.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using System.Configuration;
-
-namespace DynaCache.RedisCache.Configuration.Redis
-{
- public class Endpoint : ConfigurationElement
- {
- internal const string EndpointNodeName = "endpoint";
- private const string AddressNodeName = "address";
- private const string PortNodeName = "port";
-
- [ConfigurationProperty(AddressNodeName, IsKey = false, IsRequired = true)]
- public string Address => (string)base[AddressNodeName];
-
- [ConfigurationProperty(PortNodeName, IsKey = true, IsRequired = false)]
- public string Port => (string)base[PortNodeName];
-
- public override string ToString()
- {
- return $"{{{nameof(Address)} = {Address}, {nameof(Port)} = {Port}}}";
- }
- }
-}
\ No newline at end of file
diff --git a/DynaCache.RedisCache/Configuration/Redis/Endpoints.cs b/DynaCache.RedisCache/Configuration/Redis/Endpoints.cs
deleted file mode 100644
index 044b945..0000000
--- a/DynaCache.RedisCache/Configuration/Redis/Endpoints.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using System.Configuration;
-using System.Text;
-
-namespace DynaCache.RedisCache.Configuration.Redis
-{
- [ConfigurationCollection(typeof(Endpoint), AddItemName = Endpoint.EndpointNodeName)]
- public class Endpoints : ConfigurationElementCollection
- {
- protected override ConfigurationElement CreateNewElement()
- {
- return new Endpoint();
- }
-
- protected override object GetElementKey(ConfigurationElement element)
- {
- var e = (Endpoint)element;
- var builder = new StringBuilder();
- builder.Append(e.Address);
- if (e.Port != null)
- builder.Append(':').Append(e.Port);
- return builder.ToString();
- }
- }
-}
\ No newline at end of file
diff --git a/DynaCache.RedisCache/Configuration/Redis/RedisConfiguration.cs b/DynaCache.RedisCache/Configuration/Redis/RedisConfiguration.cs
deleted file mode 100644
index 7ed0dcb..0000000
--- a/DynaCache.RedisCache/Configuration/Redis/RedisConfiguration.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using System.Configuration;
-
-namespace DynaCache.RedisCache.Configuration.Redis
-{
- public class RedisConfiguration : ConfigurationSection
- {
- private const string EndpointsNodeName = "endpoints";
- private const string SyncTimeoutNodeName = "syncTimeout";
-
- [ConfigurationProperty(EndpointsNodeName)]
- public Endpoints Endpoints => (Endpoints)base[EndpointsNodeName];
-
- [ConfigurationProperty(SyncTimeoutNodeName)]
- public string SyncTimeout => (string)base[SyncTimeoutNodeName];
- }
-}
\ No newline at end of file
diff --git a/DynaCache.RedisCache/Configuration/RedisConfigurationProviderService.cs b/DynaCache.RedisCache/Configuration/RedisConfigurationProviderService.cs
deleted file mode 100644
index 18d3af2..0000000
--- a/DynaCache.RedisCache/Configuration/RedisConfigurationProviderService.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using System.Configuration;
-using System.Linq;
-using DynaCache.RedisCache.Configuration.Redis;
-using DynaCache.RedisCache.Internals;
-using Functional.Maybe;
-using NLog;
-using StackExchange.Redis;
-
-namespace DynaCache.RedisCache.Configuration
-{
- internal class RedisConfigurationProviderService : IRedisConfigurationProviderService
- {
- private const string RedisSectionName = "redis";
-
- private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
-
- private readonly RedisConfiguration _redisSection;
-
- public RedisConfigurationProviderService()
- {
- _redisSection = (RedisConfiguration)ConfigurationManager.GetSection(RedisSectionName);
- }
-
- public ConfigurationOptions GetMultiplexorOptions()
- {
- var res = new ConfigurationOptions();
- _redisSection.Endpoints
- .Cast()
- .Select(e => new {Host = e.Address, PortMaybe = e.Port.ParseMaybe(ushort.TryParse), PortRaw = e.Port})
- .ToList()
- .Select(e => new {e.Host, PortMaybe = e.PortMaybe.Match(p => { }, () => logger.Error($"failed to parse {e.PortRaw} as ip port"))})
- .Where(e => e.PortMaybe.HasValue)
- .ToList()
- .ForEach(e => res.EndPoints.Add(e.Host, e.PortMaybe.Value));
-
- _redisSection.SyncTimeout.ParseMaybe(int.TryParse).Do(t => res.SyncTimeout = t);
-
- return res;
- }
- }
-}
\ No newline at end of file
diff --git a/DynaCache.RedisCache/DynaCache.RedisCache.csproj b/DynaCache.RedisCache/DynaCache.RedisCache.csproj
deleted file mode 100644
index 9a4ddb3..0000000
--- a/DynaCache.RedisCache/DynaCache.RedisCache.csproj
+++ /dev/null
@@ -1,101 +0,0 @@
-
-
-
-
- Debug
- AnyCPU
- {1B57BF04-E33F-4DCA-AF58-B02E6EC71130}
- Library
- Properties
- DynaCache.RedisCache
- DynaCache.RedisCache
- v4.5.1
- 512
-
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
- ..\packages\Functional.Maybe.1.1.0\lib\portable40-net40+win8\Functional.Maybe.dll
- True
-
-
- ..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll
- True
-
-
- ..\packages\NLog.4.3.1\lib\net45\NLog.dll
- True
-
-
- ..\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll
- True
-
-
- ..\packages\StackExchange.Redis.1.0.488\lib\net45\StackExchange.Redis.dll
- True
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {F4EE6A5E-A9EC-4119-A8E3-A1D270732D0D}
- DynaCache
-
-
- {3ABC04DB-454F-4543-99E3-84BF6875DA95}
- NLog.Extension
-
-
-
-
- Designer
-
-
-
-
-
\ No newline at end of file
diff --git a/DynaCache.RedisCache/Internals/Extensions.cs b/DynaCache.RedisCache/Internals/Extensions.cs
deleted file mode 100644
index b518c4e..0000000
--- a/DynaCache.RedisCache/Internals/Extensions.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using System.Text;
-using Functional.Maybe;
-
-namespace DynaCache.RedisCache.Internals
-{
- internal static class StringBuilderExtensions
- {
- public static StringBuilder AppendIfNotEmpty(this StringBuilder builder, char that)
- {
- return builder.Length > 0
- ? builder.Append(that)
- : builder;
- }
- }
-
- internal static class StringExtensions
- {
- public static Maybe ParseMaybe(this string that, ParseDelegate parser)
- {
- T res;
- return parser(that, out res)
- ? res.ToMaybe()
- : Maybe.Nothing;
- }
-
- internal delegate bool ParseDelegate(string val, out T res);
- }
-}
\ No newline at end of file
diff --git a/DynaCache.RedisCache/Internals/ICacheSerializer.cs b/DynaCache.RedisCache/Internals/ICacheSerializer.cs
deleted file mode 100644
index b1a6dc7..0000000
--- a/DynaCache.RedisCache/Internals/ICacheSerializer.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-namespace DynaCache.RedisCache.Internals
-{
- public interface ICacheSerializer
- {
- string Serialize(T @object);
- T Deserialize(string @object);
- }
-}
\ No newline at end of file
diff --git a/DynaCache.RedisCache/Internals/ProtobufCacheSerializer.cs b/DynaCache.RedisCache/Internals/ProtobufCacheSerializer.cs
deleted file mode 100644
index c2e498a..0000000
--- a/DynaCache.RedisCache/Internals/ProtobufCacheSerializer.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using System.IO;
-using System.Text;
-using NLog;
-using NLog.Extension;
-using ProtoBuf;
-
-namespace DynaCache.RedisCache.Internals
-{
- internal class ProtobufCacheSerializer : ICacheSerializer
- {
- private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
-
- public string Serialize(T @object)
- {
- using (new TracingLogProxy(logger))
- using (var stream = new MemoryStream())
- {
- Serializer.Serialize(stream, @object);
- var bytes = stream.ToArray();
- return Encoding.Default.GetString(bytes);
- }
- }
-
- public T Deserialize(string @object)
- {
- using (new TracingLogProxy(logger))
- {
- var bytes = Encoding.Default.GetBytes(@object.ToCharArray());
- using (var stream = new MemoryStream(bytes))
- return Serializer.Deserialize(stream);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/DynaCache.RedisCache/Internals/RedisService.cs b/DynaCache.RedisCache/Internals/RedisService.cs
deleted file mode 100644
index fe2d0c4..0000000
--- a/DynaCache.RedisCache/Internals/RedisService.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using System;
-using DynaCache.RedisCache.Configuration;
-using StackExchange.Redis;
-
-namespace DynaCache.RedisCache.Internals
-{
- public interface IRedisService
- {
- IDatabase Database { get; }
- }
-
- // Should be used as a single instance only
- internal class RedisService : IRedisService, IDisposable
- {
- private readonly ConnectionMultiplexer _multiplexer;
-
- public RedisService(IRedisConfigurationProviderService configurationProviderService)
- {
- var options = configurationProviderService.GetMultiplexorOptions();
-
- _multiplexer = ConnectionMultiplexer.Connect(options);
- }
-
- public void Dispose()
- => _multiplexer.Dispose();
-
- public IDatabase Database => _multiplexer.GetDatabase();
- }
-}
\ No newline at end of file
diff --git a/DynaCache.RedisCache/Properties/AssemblyInfo.cs b/DynaCache.RedisCache/Properties/AssemblyInfo.cs
deleted file mode 100644
index 85d67f7..0000000
--- a/DynaCache.RedisCache/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-
-[assembly: AssemblyTitle("DynaCache.RedisCache")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("DynaCache.RedisCache")]
-[assembly: AssemblyCopyright("Copyright © 2016")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-
-[assembly: Guid("1b57bf04-e33f-4dca-af58-b02e6ec71130")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
\ No newline at end of file
diff --git a/DynaCache.RedisCache/RedisCacheModule.cs b/DynaCache.RedisCache/RedisCacheModule.cs
deleted file mode 100644
index 807a75c..0000000
--- a/DynaCache.RedisCache/RedisCacheModule.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using DynaCache.RedisCache.Configuration;
-using DynaCache.RedisCache.Internals;
-using Ninject.Modules;
-
-namespace DynaCache.RedisCache
-{
- public class RedisCacheModule : NinjectModule
- {
- public override void Load()
- {
- Bind().To().InSingletonScope();
- Bind().To().InSingletonScope();
- Bind().To();
- }
- }
-}
diff --git a/DynaCache.RedisCache/RedisCacheService.cs b/DynaCache.RedisCache/RedisCacheService.cs
deleted file mode 100644
index 6583885..0000000
--- a/DynaCache.RedisCache/RedisCacheService.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-using DynaCache.RedisCache.Internals;
-using NLog;
-using NLog.Extension;
-using System;
-
-namespace DynaCache.RedisCache
-{
- public class RedisCacheService : IDynaCacheService
- {
- private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
- private readonly IRedisService _redisService;
- private readonly ICacheSerializer _serializer;
-
- public RedisCacheService(IRedisService redisService, ICacheSerializer serializer)
- {
- _redisService = redisService;
- _serializer = serializer;
- }
-
- public bool TryGetCachedObject(string cacheKey, out T result)
- {
- using (new TracingLogProxy(logger))
- {
- result = default(T);
- logger.Debug($"cache for {cacheKey} requested");
- var res = _redisService.Database.StringGet(cacheKey);
- var notFound = res.IsNull;
- if (notFound)
- {
- logger.Debug($"cache not found for {cacheKey}");
- return false;
- }
- var serialized = res.ToString();
- logger.Debug($"found cache for {cacheKey}");
- try
- {
- result = _serializer.Deserialize(serialized);
- return true;
- }
- catch (Exception e)
- {
- logger.Error(e, $"failed to deserialize cache for {cacheKey}");
- return false;
- }
- }
- }
-
- public void SetCachedObject(string cacheKey, T data, int duration)
- {
- using (new TracingLogProxy(logger))
- {
- var expiration = TimeSpan.FromSeconds(duration);
- logger.Debug($"storing cache for {cacheKey} with expiry {expiration}");
- var serialized = _serializer.Serialize(data);
- _redisService.Database.StringSet(cacheKey, serialized, expiration);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/DynaCache.RedisCache/packages.config b/DynaCache.RedisCache/packages.config
deleted file mode 100644
index 2f4c0f2..0000000
--- a/DynaCache.RedisCache/packages.config
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/DynaCache.TestApp/ClassDiagram1.cd b/DynaCache.TestApp/ClassDiagram1.cd
deleted file mode 100644
index 837b867..0000000
--- a/DynaCache.TestApp/ClassDiagram1.cd
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-
-
-
- AAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAQAAAAAAAA=
- RandomService.cs
-
-
-
-
-
\ No newline at end of file
diff --git a/DynaCache.TestApp/DynaCache.TestApp.csproj b/DynaCache.TestApp/DynaCache.TestApp.csproj
deleted file mode 100644
index 8db4f0d..0000000
--- a/DynaCache.TestApp/DynaCache.TestApp.csproj
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
- Debug
- x86
- 8.0.30703
- 2.0
- {04918D75-7003-4AD3-961D-9CC7466C684A}
- Exe
- Properties
- DynaCache.TestApp
- DynaCache.TestApp
- v4.5.1
-
-
- 512
- SAK
- SAK
- SAK
- SAK
-
-
- AnyCPU
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- x86
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
- false
-
-
-
- ..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll
- True
-
-
-
-
-
-
-
-
-
-
-
-
-
- Properties\CommonAssemblyInfo.cs
-
-
-
-
-
-
-
-
-
- DynaCache.snk
-
-
-
-
-
-
- {F4EE6A5E-A9EC-4119-A8E3-A1D270732D0D}
- DynaCache
-
-
-
-
-
\ No newline at end of file
diff --git a/DynaCache.TestApp/DynaCache.TestApp.csproj.vspscc b/DynaCache.TestApp/DynaCache.TestApp.csproj.vspscc
deleted file mode 100644
index b6d3289..0000000
--- a/DynaCache.TestApp/DynaCache.TestApp.csproj.vspscc
+++ /dev/null
@@ -1,10 +0,0 @@
-""
-{
-"FILE_VERSION" = "9237"
-"ENLISTMENT_CHOICE" = "NEVER"
-"PROJECT_FILE_RELATIVE_PATH" = ""
-"NUMBER_OF_EXCLUDED_FILES" = "0"
-"ORIGINAL_PROJECT_FILE_PATH" = ""
-"NUMBER_OF_NESTED_PROJECTS" = "0"
-"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
-}
diff --git a/DynaCache.TestApp/Program.cs b/DynaCache.TestApp/Program.cs
deleted file mode 100644
index 0c2a94d..0000000
--- a/DynaCache.TestApp/Program.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-#region Copyright 2012 Mike Goatly
-// This source is subject to the the MIT License (MIT)
-// All rights reserved.
-#endregion
-
-namespace DynaCache.TestApp
-{
- using System;
- using System.Threading;
- using Ninject;
-
- ///
- /// A simple test application to demonstrate the use of the DynaCache library.
- ///
- public class Program
- {
- ///
- /// The main application entry point.
- ///
- public static void Main()
- {
- // Using ninject to do the dependency injection - there's no reason why you shouldn't use something else though.
- var kernel = new StandardKernel();
-
- // Bind the IDynaCacheService to the our sample memory cache service.
- kernel.Bind().To();
-
- // Bind our test service interface to its _cacheable_ concrete implementation
- kernel.Bind().To(Cacheable.CreateType());
-
- // Use the DI container to construct our cacheable concrete instance of ITestService
- var service = kernel.Get();
-
- for (var i = 0; i < 12; i++)
- {
- // The result from the GetRandomNumber method on the service has its results cached for 1 second
- // therefore the displayed results should only change every 4th iteration.
- Console.WriteLine("Random number between 1 and 10: {0}", service.GetRandomNumber(1, 10));
- Console.WriteLine("Random number between 1 and 20: {0}", service.GetRandomNumber(1, 20));
-
- Thread.Sleep(250);
- }
- }
- }
-}
diff --git a/DynaCache.TestApp/Properties/AssemblyInfo.cs b/DynaCache.TestApp/Properties/AssemblyInfo.cs
deleted file mode 100644
index 5d5ee36..0000000
--- a/DynaCache.TestApp/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-#region Copyright 2012 Mike Goatly
-// This source is subject to the the MIT License (MIT)
-// All rights reserved.
-#endregion
-
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-[assembly: AssemblyTitle("DynaCache.TestApp")]
-[assembly: AssemblyDescription("")]
-[assembly: Guid("607be8a2-fc05-44db-b138-8efbd9e78ef5")]
diff --git a/DynaCache.TestApp/TestMemoryCacheService.cs b/DynaCache.TestApp/TestMemoryCacheService.cs
deleted file mode 100644
index d20928e..0000000
--- a/DynaCache.TestApp/TestMemoryCacheService.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-#region Copyright 2012 Mike Goatly
-// This source is subject to the the MIT License (MIT)
-// All rights reserved.
-#endregion
-
-using System;
-using System.Runtime.Caching;
-
-namespace DynaCache.TestApp
-{
- ///
- /// A sample memory cache that additionally outputs to the console window when data is stored
- /// and read from the cache.
- ///
- public class TestMemoryCacheService : IDynaCacheService
- {
- ///
- /// The in-memory cache.
- ///
- private readonly MemoryCache _cache = new MemoryCache("CacheService");
-
- ///
- /// Tries to get a cached object from the cache using the given cache key.
- ///
- /// The cache key of the object to read from the cache.
- /// The object that was read from the cache, or null if the key
- /// could not be found in the cache.
- /// true if the item could be read from the cache, otherwise false.
- public virtual bool TryGetCachedObject(string cacheKey, out T result)
- {
- result = default(T);
- if (_cache.Contains(cacheKey))
- {
- var res = _cache[cacheKey];
- if (!(res is T))
- {
- Console.ForegroundColor = ConsoleColor.DarkRed;
- Console.WriteLine("invalid cached data type for key {0}", cacheKey);
- return false;
- }
- result = (T)_cache[cacheKey];
- Console.ForegroundColor = ConsoleColor.DarkGreen;
- Console.WriteLine("Read {0} from cache key {1}", result, cacheKey);
- Console.ResetColor();
- return true;
- }
-
- Console.ForegroundColor = ConsoleColor.DarkRed;
- Console.WriteLine("Cache miss for cache key {0}", cacheKey);
- return false;
- }
-
- ///
- /// Stores an object in the cache.
- ///
- /// The cache key to store the object against.
- /// The data to store against the key.
- /// The duration, in seconds, to cache the data for.
- public virtual void SetCachedObject(string cacheKey, T data, int duration)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Caching {0} against {1} for {2}s", data, cacheKey, duration);
- Console.ResetColor();
- _cache.Add(cacheKey, data, DateTime.Now.AddSeconds(duration));
- }
- }
-}
diff --git a/DynaCache.TestApp/app.config b/DynaCache.TestApp/app.config
deleted file mode 100644
index 37fee69..0000000
--- a/DynaCache.TestApp/app.config
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
diff --git a/DynaCache.TestApp/packages.config b/DynaCache.TestApp/packages.config
deleted file mode 100644
index e89e064..0000000
--- a/DynaCache.TestApp/packages.config
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/DynaCache.Tests/App.config b/DynaCache.Tests/App.config
deleted file mode 100644
index 2013b6f..0000000
--- a/DynaCache.Tests/App.config
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/DynaCache.Tests/AspNetCacheServiceTests.cs b/DynaCache.Tests/AspNetCacheServiceTests.cs
deleted file mode 100644
index c7bd4f8..0000000
--- a/DynaCache.Tests/AspNetCacheServiceTests.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-#region Copyright 2012 Mike Goatly
-// This source is subject to the the MIT License (MIT)
-// All rights reserved.
-#endregion
-
-namespace DynaCache.Tests
-{
- using System.Threading;
-
- using AspNetCache;
-
- using Microsoft.VisualStudio.TestTools.UnitTesting;
-
- ///
- /// Tests for the MemoryCacheService class.
- ///
- [TestClass]
- public class AspNetCacheServiceTests
- {
- ///
- /// If an item is not in the cache when TryGetCachedObject is called, false should be returned.
- ///
- [TestMethod]
- public void ShouldReturnFalseIfItemNotInCache()
- {
- var cache = new AspNetCacheService();
-
- object result;
- Assert.IsFalse(cache.TryGetCachedObject("key1", out result));
- Assert.IsNull(result);
- }
-
- ///
- /// If an item is in the cache when TryGetCachedObject is called, true should be returned
- /// and the result parameter should be set.
- ///
- [TestMethod]
- public void ShouldReturnTrueIfItemInCache()
- {
- var cache = new AspNetCacheService();
-
- cache.SetCachedObject("key2", "Boom", 1);
-
- object result;
- Assert.IsTrue(cache.TryGetCachedObject("key2", out result));
- Assert.AreEqual("Boom", result);
- }
-
- ///
- /// If an item is not in the cache when TryGetCachedObject is called because it has expired, false should be
- /// returned.
- ///
- [TestMethod]
- public void ShouldReturnFalseIfItemInCacheExpired()
- {
- var cache = new AspNetCacheService();
-
- cache.SetCachedObject("key3", "Boom", 1);
-
- Thread.Sleep(1200);
-
- object result;
- Assert.IsFalse(cache.TryGetCachedObject("key3", out result));
- Assert.IsNull(result);
- }
- }
-}
diff --git a/DynaCache.Tests/CallingCachedMethod.cs b/DynaCache.Tests/CallingCachedMethod.cs
deleted file mode 100644
index 998ce8c..0000000
--- a/DynaCache.Tests/CallingCachedMethod.cs
+++ /dev/null
@@ -1,196 +0,0 @@
-#region Copyright 2012 Mike Goatly
-// This source is subject to the the MIT License (MIT)
-// All rights reserved.
-#endregion
-
-using DynaCache.MemoryCache;
-using System.Linq;
-using NSubstitute;
-
-namespace DynaCache.Tests
-{
- using System;
-
- using TestClasses;
-
- using Microsoft.VisualStudio.TestTools.UnitTesting;
-
- using Moq;
- using System.Diagnostics;
- using System.Reflection;
-
- ///
- /// The calling cached method.
- ///
- [TestClass]
- public class CallingCachedMethod
- {
- ///
- /// Named cache durations should be used successfully.
- ///
- [TestMethod]
- public void ShouldReadCorrectConfigurationFromNamedCacheDurations()
- {
- const string keyNameA = "DynaCache.Tests.TestClasses.NamedCacheableMethodTester_System.String[] Execute(System.String).Hello world";
- const string keyNameB = "DynaCache.Tests.TestClasses.NamedCacheableMethodTester_Int32 Execute(System.DateTime).2014-11-01T00:00:00.0000000";
-
- var cacheService = Substitute.For();
- var cacheableType = Cacheable.CreateType();
-
- var instance = (ICacheableMethodsTester)Activator.CreateInstance(cacheableType, cacheService);
-
- string[] resultA;
- int resultB;
- cacheService.TryGetCachedObject(keyNameA, out resultA).Returns(false);
- cacheService.TryGetCachedObject(keyNameB, out resultB).Returns(false);
-
- var responseA = instance.Execute("Hello world");
- cacheService.Received(1).TryGetCachedObject(keyNameA, out resultA);
- cacheService.Received(1).SetCachedObject(keyNameA, responseA, 1);
- var responseB = instance.Execute(new DateTime(2014, 11, 1));
- cacheService.Received(1).TryGetCachedObject(keyNameB, out resultB);
- cacheService.Received(1).SetCachedObject(keyNameB, responseB, 60);
- }
-
- ///
- /// The first time a method is called, the cache will not contain the key and
- /// the base method should be called - the result of which should be cached.
- ///
- [TestMethod]
- public void ShouldWriteToCacheServiceOnFirstCall()
- {
- const string keyName = "DynaCache.Tests.TestClasses.OneCacheableMethodTester_System.String[] Execute(System.String).Hello world";
-
- var cacheService = Substitute.For();
- var cacheableType = Cacheable.CreateType();
-
- var instance = (ICacheableMethodsTester)Activator.CreateInstance(cacheableType, cacheService);
-
- object result;
- cacheService.TryGetCachedObject(keyName, out result).Returns(false);
-
- var response = instance.Execute("Hello world");
-
- cacheService.Received(1).TryGetCachedObject(keyName, out result);
- cacheService.Received(1).SetCachedObject(keyName, response, 100);
- }
-
- ///
- /// Verifies that a key is created successfully for a method on a generic class.
- ///
- [TestMethod]
- public void ShouldReadWithCorrectKeyForGenericClass()
- {
- const string keyName = "DynaCache.Tests.TestClasses.GenericTester`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]_System.String Convert(Int32).199";
-
- var cacheService = Substitute.For();
- var cacheableType = Cacheable.CreateType>();
-
- var instance = (IGenericTester)Activator.CreateInstance(cacheableType, cacheService);
-
- string result;
- cacheService.TryGetCachedObject(keyName, out result).Returns(true);
-
- instance.Convert(199);
-
- cacheService.Received(1).TryGetCachedObject(keyName, out result);
- cacheService.DidNotReceive().SetCachedObject(keyName, Arg.Any