-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from dncsvr/feature/request-cache
Feature / Request Cache
- Loading branch information
Showing
18 changed files
with
183 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Caching | ||
|
||
Implementations of this feature provides predefined caching behaviour. | ||
|
||
Add this feature using `AddCaching()` extension; | ||
|
||
```csharp | ||
app.Features.AddCaching(...); | ||
``` | ||
|
||
## Scoped Memory | ||
|
||
This feature implementation registers `Func<IMemoryCache>` factory with scoped | ||
`MemoryCache` implementation to provide request in-memory caching. | ||
|
||
```csharp | ||
c => c.ScopedMemory() | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/blueprints/Do.Blueprints.Service.Application/Caching/CachingConfigurator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Do.Caching; | ||
|
||
public class CachingConfigurator { } |
9 changes: 9 additions & 0 deletions
9
src/blueprints/Do.Blueprints.Service.Application/Caching/CachingExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Do.Architecture; | ||
using Do.Caching; | ||
|
||
namespace Do; | ||
|
||
public static class CachingExtensions | ||
{ | ||
public static void AddCaching(this List<IFeature> source, Func<CachingConfigurator, IFeature<CachingConfigurator>> configure) => source.Add(configure(new())); | ||
} |
9 changes: 9 additions & 0 deletions
9
...s/Do.Blueprints.Service.Application/Caching/ScopedMemory/ScopedMemoryCachingExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Do.Caching; | ||
using Do.Caching.ScopedMemory; | ||
|
||
namespace Do; | ||
|
||
public static class ScopedMemoryCachingExtensions | ||
{ | ||
public static ScopedMemoryCachingFeature ScopedMemory(this CachingConfigurator _) => new(); | ||
} |
15 changes: 15 additions & 0 deletions
15
...ints/Do.Blueprints.Service.Application/Caching/ScopedMemory/ScopedMemoryCachingFeature.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Do.Architecture; | ||
using Microsoft.Extensions.Caching.Memory; | ||
|
||
namespace Do.Caching.ScopedMemory; | ||
|
||
public class ScopedMemoryCachingFeature : IFeature<CachingConfigurator> | ||
{ | ||
public void Configure(LayerConfigurator configurator) | ||
{ | ||
configurator.ConfigureServiceCollection(services => | ||
{ | ||
services.AddScopedWithFactory<IMemoryCache, MemoryCache>(); | ||
}); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/blueprints/Do.Blueprints.Service.Application/Database/MySql/CustomMySQL57Dialect.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using NHibernate.Dialect; | ||
using System.Data; | ||
|
||
namespace Do.Database.MySql; | ||
|
||
public class CustomMySQL57Dialect : MySQL57Dialect | ||
{ | ||
public CustomMySQL57Dialect() | ||
{ | ||
RegisterColumnType(DbType.String, 1023, "VARCHAR($l)"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
test/blueprints/Do.Test.Blueprints.Service.Test/Caching/UsingScopedMemory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Microsoft.Extensions.Caching.Memory; | ||
|
||
namespace Do.Test.Caching; | ||
|
||
public class UsingScopedMemory : TestServiceSpec | ||
{ | ||
public override void TearDown() | ||
{ | ||
base.TearDown(); | ||
|
||
GiveMe.AMemoryCache().ShouldHaveCount(0); | ||
} | ||
|
||
[Test] | ||
public void Objects_can_be_cached_in__scoped_memory() | ||
{ | ||
var cache = GiveMe.AMemoryCache(); | ||
var expected = cache.GetOrCreate<object>("key", _ => new()); | ||
|
||
var actual = cache.GetOrCreate<object>("key", _ => new()); | ||
|
||
actual.ShouldBeSameAs(expected); | ||
cache.ShouldHaveCount(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
# Unreleased | ||
|
||
## Features | ||
|
||
- Beta features are available in do-blueprints-service package; | ||
- `Caching` feature is now added with `ScopedMemory` implementation | ||
|
||
## Improvements | ||
|
||
- Added `CustomMySQL57Dialect` for enabling `varchar` column type with _1023_ | ||
max capacity | ||
- Added `TransientWithFactory<TService, TImplementation>` and | ||
`ScopedWithFactory<TService, TImplementation>` extensions for registering | ||
services with implementations | ||
- Added new ServiceSpec extensions: | ||
- `AnInteger` extension for `Stubber` | ||
- `AMemoryCache` extension for `Stubber` | ||
- `ShouldHaveCount` extension for `IMemoryCache` |