Skip to content

Commit 111ccf4

Browse files
Add a .Net Core memory cache
* Upgrade log4net to 2.0.8 in all projects * Upgrade AsyncGenerator and regenerate all projects * Handle compilation with multiple target frameworks * Handle Core tests Fixes #25
1 parent fbbe23b commit 111ccf4

File tree

44 files changed

+1384
-181
lines changed

Some content is hidden

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

44 files changed

+1384
-181
lines changed

AsyncGenerator.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,33 @@
11
projects:
2+
- filePath: CoreMemoryCache\NHibernate.Caches.CoreMemoryCache\NHibernate.Caches.CoreMemoryCache.csproj
3+
targetFramework: net461
4+
concurrentRun: true
5+
applyChanges: true
6+
analyzation:
7+
methodConversion:
8+
- conversion: Ignore
9+
hasAttributeName: ObsoleteAttribute
10+
callForwarding: true
11+
cancellationTokens:
12+
guards: true
13+
methodParameter:
14+
- anyInterfaceRule: PubliclyExposedType
15+
parameter: Optional
16+
- parameter: Optional
17+
rule: PubliclyExposedType
18+
- parameter: Required
19+
scanMethodBody: true
20+
scanForMissingAsyncMembers:
21+
- all: true
22+
transformation:
23+
configureAwaitArgument: false
24+
localFunctions: true
25+
asyncLock:
26+
type: NHibernate.Util.AsyncLock
27+
methodName: LockAsync
28+
registerPlugin:
29+
- type: AsyncGenerator.Core.Plugins.EmptyRegionRemover
30+
assemblyName: AsyncGenerator.Core
231
- filePath: EnyimMemcached\NHibernate.Caches.EnyimMemcached\NHibernate.Caches.EnyimMemcached.csproj
332
concurrentRun: true
433
applyChanges: true
@@ -224,6 +253,48 @@
224253
- type: AsyncGenerator.Core.Plugins.EmptyRegionRemover
225254
assemblyName: AsyncGenerator.Core
226255
- filePath: NHibernate.Caches.Common.Tests\NHibernate.Caches.Common.Tests.csproj
256+
targetFramework: net461
257+
concurrentRun: true
258+
applyChanges: true
259+
analyzation:
260+
methodConversion:
261+
- conversion: Ignore
262+
hasAttributeName: OneTimeSetUpAttribute
263+
- conversion: Ignore
264+
hasAttributeName: OneTimeTearDownAttribute
265+
- conversion: Ignore
266+
hasAttributeName: SetUpAttribute
267+
- conversion: Ignore
268+
hasAttributeName: TearDownAttribute
269+
- conversion: Smart
270+
hasAttributeName: TestAttribute
271+
- conversion: Smart
272+
hasAttributeName: TheoryAttribute
273+
preserveReturnType:
274+
- hasAttributeName: TestAttribute
275+
- hasAttributeName: TheoryAttribute
276+
typeConversion:
277+
- conversion: Ignore
278+
hasAttributeName: IgnoreAttribute
279+
- conversion: Partial
280+
hasAttributeName: TestFixtureAttribute
281+
- conversion: Partial
282+
anyBaseTypeRule: HasTestFixtureAttribute
283+
ignoreSearchForMethodReferences:
284+
- hasAttributeName: TheoryAttribute
285+
- hasAttributeName: TestAttribute
286+
cancellationTokens:
287+
withoutCancellationToken:
288+
- hasAttributeName: TestAttribute
289+
- hasAttributeName: TheoryAttribute
290+
scanMethodBody: true
291+
scanForMissingAsyncMembers:
292+
- all: true
293+
registerPlugin:
294+
- type: AsyncGenerator.Core.Plugins.NUnitAsyncCounterpartsFinder
295+
assemblyName: AsyncGenerator.Core
296+
- filePath: CoreMemoryCache\NHibernate.Caches.CoreMemoryCache.Tests\NHibernate.Caches.CoreMemoryCache.Tests.csproj
297+
targetFramework: net461
227298
concurrentRun: true
228299
applyChanges: true
229300
analyzation:
@@ -264,6 +335,7 @@
264335
- type: AsyncGenerator.Core.Plugins.NUnitAsyncCounterpartsFinder
265336
assemblyName: AsyncGenerator.Core
266337
- filePath: EnyimMemcached\NHibernate.Caches.EnyimMemcached.Tests\NHibernate.Caches.EnyimMemcached.Tests.csproj
338+
targetFramework: net461
267339
concurrentRun: true
268340
applyChanges: true
269341
analyzation:
@@ -304,6 +376,7 @@
304376
- type: AsyncGenerator.Core.Plugins.NUnitAsyncCounterpartsFinder
305377
assemblyName: AsyncGenerator.Core
306378
- filePath: MemCache\NHibernate.Caches.MemCache.Tests\NHibernate.Caches.MemCache.Tests.csproj
379+
targetFramework: net461
307380
concurrentRun: true
308381
applyChanges: true
309382
analyzation:
@@ -344,6 +417,7 @@
344417
- type: AsyncGenerator.Core.Plugins.NUnitAsyncCounterpartsFinder
345418
assemblyName: AsyncGenerator.Core
346419
- filePath: Prevalence\NHibernate.Caches.Prevalence.Tests\NHibernate.Caches.Prevalence.Tests.csproj
420+
targetFramework: net461
347421
concurrentRun: true
348422
applyChanges: true
349423
analyzation:
@@ -384,6 +458,7 @@
384458
- type: AsyncGenerator.Core.Plugins.NUnitAsyncCounterpartsFinder
385459
assemblyName: AsyncGenerator.Core
386460
- filePath: RtMemoryCache\NHibernate.Caches.RtMemoryCache.Tests\NHibernate.Caches.RtMemoryCache.Tests.csproj
461+
targetFramework: net461
387462
concurrentRun: true
388463
applyChanges: true
389464
analyzation:
@@ -424,6 +499,7 @@
424499
- type: AsyncGenerator.Core.Plugins.NUnitAsyncCounterpartsFinder
425500
assemblyName: AsyncGenerator.Core
426501
- filePath: SharedCache\NHibernate.Caches.SharedCache.Tests\NHibernate.Caches.SharedCache.Tests.csproj
502+
targetFramework: net461
427503
concurrentRun: true
428504
applyChanges: true
429505
analyzation:
@@ -464,6 +540,7 @@
464540
- type: AsyncGenerator.Core.Plugins.NUnitAsyncCounterpartsFinder
465541
assemblyName: AsyncGenerator.Core
466542
- filePath: SysCache\NHibernate.Caches.SysCache.Tests\NHibernate.Caches.SysCache.Tests.csproj
543+
targetFramework: net461
467544
concurrentRun: true
468545
applyChanges: true
469546
analyzation:
@@ -504,6 +581,7 @@
504581
- type: AsyncGenerator.Core.Plugins.NUnitAsyncCounterpartsFinder
505582
assemblyName: AsyncGenerator.Core
506583
- filePath: SysCache2\NHibernate.Caches.SysCache2.Tests\NHibernate.Caches.SysCache2.Tests.csproj
584+
targetFramework: net461
507585
concurrentRun: true
508586
applyChanges: true
509587
analyzation:
@@ -544,6 +622,7 @@
544622
- type: AsyncGenerator.Core.Plugins.NUnitAsyncCounterpartsFinder
545623
assemblyName: AsyncGenerator.Core
546624
- filePath: Velocity\NHibernate.Caches.Velocity.Tests\NHibernate.Caches.Velocity.Tests.csproj
625+
targetFramework: net461
547626
concurrentRun: true
548627
applyChanges: true
549628
analyzation:
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<configSections>
4+
<section name="corememorycache" type="NHibernate.Caches.CoreMemoryCache.CoreMemoryCacheSectionHandler,NHibernate.Caches.CoreMemoryCache" />
5+
<section name="hibernate-configuration"
6+
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
7+
</configSections>
8+
9+
<corememorycache expiration-scan-frequency="00:05:00">
10+
<cache region="foo" expiration="500" sliding="true" />
11+
<cache region="noExplicitExpiration" sliding="true" />
12+
</corememorycache>
13+
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
14+
<session-factory>
15+
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
16+
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
17+
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
18+
<property name="connection.connection_string">
19+
Server=localhost;initial catalog=nhibernate;Integrated Security=SSPI
20+
</property>
21+
<property name="cache.provider_class">NHibernate.Caches.CoreMemoryCache.CoreMemoryCacheProvider,NHibernate.Caches.CoreMemoryCache</property>
22+
</session-factory>
23+
</hibernate-configuration>
24+
</configuration>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#region License
2+
3+
//
4+
// CoreMemoryCache - A cache provider for NHibernate using Microsoft.Extensions.Caching.Memory.
5+
//
6+
// This library is free software; you can redistribute it and/or
7+
// modify it under the terms of the GNU Lesser General Public
8+
// License as published by the Free Software Foundation; either
9+
// version 2.1 of the License, or (at your option) any later version.
10+
//
11+
// This library is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
// Lesser General Public License for more details.
15+
//
16+
// You should have received a copy of the GNU Lesser General Public
17+
// License along with this library; if not, write to the Free Software
18+
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19+
//
20+
21+
#endregion
22+
23+
using System;
24+
using NHibernate.Cache;
25+
using NHibernate.Caches.Common.Tests;
26+
using NUnit.Framework;
27+
28+
namespace NHibernate.Caches.CoreMemoryCache.Tests
29+
{
30+
[TestFixture]
31+
public class CoreMemoryCacheFixture : CacheFixture
32+
{
33+
protected override bool SupportsSlidingExpiration => true;
34+
35+
protected override Func<ICacheProvider> ProviderBuilder =>
36+
() => new CoreMemoryCacheProvider();
37+
38+
[Test]
39+
public void TestDefaultConstructor()
40+
{
41+
Assert.That(() => new CoreMemoryCache(), Throws.Nothing);
42+
}
43+
44+
[Test]
45+
public void TestNoPropertiesConstructor()
46+
{
47+
Assert.That(() => new CoreMemoryCache("TestNoPropertiesConstructor"), Throws.Nothing);
48+
}
49+
}
50+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#region License
2+
3+
//
4+
// CoreMemoryCache - A cache provider for NHibernate using Microsoft.Extensions.Caching.Memory.
5+
//
6+
// This library is free software; you can redistribute it and/or
7+
// modify it under the terms of the GNU Lesser General Public
8+
// License as published by the Free Software Foundation; either
9+
// version 2.1 of the License, or (at your option) any later version.
10+
//
11+
// This library is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
// Lesser General Public License for more details.
15+
//
16+
// You should have received a copy of the GNU Lesser General Public
17+
// License along with this library; if not, write to the Free Software
18+
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19+
//
20+
21+
#endregion
22+
23+
using System;
24+
using System.Collections.Generic;
25+
using NHibernate.Cache;
26+
using NHibernate.Caches.Common.Tests;
27+
using NUnit.Framework;
28+
29+
namespace NHibernate.Caches.CoreMemoryCache.Tests
30+
{
31+
[TestFixture]
32+
public class CoreMemoryCacheProviderFixture : CacheProviderFixture
33+
{
34+
protected override Func<ICacheProvider> ProviderBuilder =>
35+
() => new CoreMemoryCacheProvider();
36+
37+
[Test]
38+
public void TestBuildCacheFromConfig()
39+
{
40+
var cache = DefaultProvider.BuildCache("foo", null);
41+
Assert.That(cache, Is.Not.Null, "pre-configured cache not found");
42+
}
43+
44+
[Test]
45+
public void TestExpiration()
46+
{
47+
var cache = DefaultProvider.BuildCache("foo", null) as CoreMemoryCache;
48+
Assert.That(cache, Is.Not.Null, "pre-configured foo cache not found");
49+
Assert.That(cache.Expiration, Is.EqualTo(TimeSpan.FromSeconds(500)), "Unexpected expiration value for foo region");
50+
51+
cache = (CoreMemoryCache)DefaultProvider.BuildCache("noExplicitExpiration", null);
52+
Assert.That(cache.Expiration, Is.EqualTo(TimeSpan.FromSeconds(300)),
53+
"Unexpected expiration value for noExplicitExpiration region");
54+
Assert.That(cache.UseSlidingExpiration, Is.True, "Unexpected sliding value for noExplicitExpiration region");
55+
56+
cache = (CoreMemoryCache)DefaultProvider
57+
.BuildCache("noExplicitExpiration", new Dictionary<string, string> { { "expiration", "100" } });
58+
Assert.That(cache.Expiration, Is.EqualTo(TimeSpan.FromSeconds(100)),
59+
"Unexpected expiration value for noExplicitExpiration region with default expiration");
60+
61+
cache = (CoreMemoryCache)DefaultProvider
62+
.BuildCache("noExplicitExpiration", new Dictionary<string, string> { { Cfg.Environment.CacheDefaultExpiration, "50" } });
63+
Assert.That(cache.Expiration, Is.EqualTo(TimeSpan.FromSeconds(50)),
64+
"Unexpected expiration value for noExplicitExpiration region with cache.default_expiration");
65+
}
66+
67+
[Test]
68+
public void TestExpirationScanFrequency()
69+
{
70+
Assert.That(CoreMemoryCacheProvider.ExpirationScanFrequency, Is.EqualTo(TimeSpan.FromMinutes(5)));
71+
}
72+
}
73+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#region License
2+
3+
//
4+
// CoreMemoryCache - A cache provider for NHibernate using Microsoft.Extensions.Caching.Memory.
5+
//
6+
// This library is free software; you can redistribute it and/or
7+
// modify it under the terms of the GNU Lesser General Public
8+
// License as published by the Free Software Foundation; either
9+
// version 2.1 of the License, or (at your option) any later version.
10+
//
11+
// This library is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
// Lesser General Public License for more details.
15+
//
16+
// You should have received a copy of the GNU Lesser General Public
17+
// License along with this library; if not, write to the Free Software
18+
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19+
//
20+
21+
#endregion
22+
23+
using System.Xml;
24+
using NUnit.Framework;
25+
26+
namespace NHibernate.Caches.CoreMemoryCache.Tests
27+
{
28+
[TestFixture]
29+
public class CoreMemoryCacheSectionHandlerFixture
30+
{
31+
private static XmlNode GetConfigurationSection(string xml)
32+
{
33+
var doc = new XmlDocument();
34+
doc.LoadXml(xml);
35+
return doc.DocumentElement;
36+
}
37+
38+
[Test]
39+
public void TestGetConfigNullSection()
40+
{
41+
var handler = new CoreMemoryCacheSectionHandler();
42+
var section = new XmlDocument();
43+
var result = handler.Create(null, null, section);
44+
Assert.That(result, Is.Not.Null);
45+
Assert.IsTrue(result is CacheConfig[]);
46+
var caches = result as CacheConfig[];
47+
Assert.That(caches.Length, Is.EqualTo(0));
48+
}
49+
50+
[Test]
51+
public void TestGetConfigFromFile()
52+
{
53+
const string xmlSimple = "<corememorycache><cache region=\"foo\" expiration=\"500\" sliding=\"true\" /></corememorycache>";
54+
55+
var handler = new CoreMemoryCacheSectionHandler();
56+
var section = GetConfigurationSection(xmlSimple);
57+
var result = handler.Create(null, null, section);
58+
Assert.That(result, Is.Not.Null);
59+
Assert.IsTrue(result is CacheConfig[]);
60+
var caches = result as CacheConfig[];
61+
Assert.That(caches.Length, Is.EqualTo(1));
62+
Assert.That(caches[0].Properties, Does.ContainKey("cache.use_sliding_expiration"));
63+
}
64+
}
65+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="../../NHibernate.Caches.props" />
3+
<PropertyGroup>
4+
<Product>NHibernate.Caches.CoreMemoryCache</Product>
5+
<Description>Unit tests of cache provider for NHibernate using .Net Core MemoryCache (Microsoft.Extensions.Caching.Memory).</Description>
6+
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
7+
<IsTestProject>true</IsTestProject>
8+
</PropertyGroup>
9+
<PropertyGroup Condition="'$(TargetFramework)' == 'net461'">
10+
<DefineConstants>NETFX;$(DefineConstants)</DefineConstants>
11+
</PropertyGroup>
12+
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
13+
<OutputType>Exe</OutputType>
14+
<GenerateProgramFile>false</GenerateProgramFile>
15+
</PropertyGroup>
16+
<ItemGroup>
17+
<ProjectReference Include="..\..\NHibernate.Caches.Common.Tests\NHibernate.Caches.Common.Tests.csproj" />
18+
<ProjectReference Include="..\NHibernate.Caches.CoreMemoryCache\NHibernate.Caches.CoreMemoryCache.csproj" />
19+
</ItemGroup>
20+
<ItemGroup>
21+
<PackageReference Include="log4net" Version="2.0.8" />
22+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.1" />
23+
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
24+
</ItemGroup>
25+
<ItemGroup Condition="'$(TargetFramework)'=='netcoreapp2.0'">
26+
<PackageReference Include="NUnitLite" Version="3.9.0" />
27+
</ItemGroup>
28+
</Project>

0 commit comments

Comments
 (0)