Skip to content

Commit 45aa996

Browse files
(GH-613) Add new options buider extensions to the memcached caching provider
1 parent 1312709 commit 45aa996

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/DotNetToolkit.Repository.Caching.Memcached/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
```csharp
44
var options = new RepositoryOptionsBuilder()
5-
.UseCachingProvider(new MemcachedCacheProvider())
5+
.UseMemcached(...)
66
.Options;
77

88
var repo = new Repository<Customer>(options);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
namespace DotNetToolkit.Repository.Caching.Memcached
2+
{
3+
using Configuration.Options;
4+
using Utility;
5+
using JetBrains.Annotations;
6+
using System;
7+
8+
/// <summary>
9+
/// Contains various extension methods for <see cref="RepositoryOptionsBuilder" />
10+
/// </summary>
11+
public static class RepositoryOptionsBuilderExtensions
12+
{
13+
/// <summary>
14+
/// Configures the caching provider to use memcached.
15+
/// </summary>
16+
/// <param name="source">The repository options builder.</param>
17+
/// <param name="optionsAction">The options action.</param>
18+
/// <returns>The same builder instance.</returns>
19+
public static RepositoryOptionsBuilder UseMemcached([NotNull] this RepositoryOptionsBuilder source, [NotNull] Action<MemcachedCacheOptions> optionsAction)
20+
{
21+
Guard.NotNull(source, nameof(source));
22+
Guard.NotNull(optionsAction, nameof(optionsAction));
23+
24+
var options = new MemcachedCacheOptions();
25+
26+
optionsAction(options);
27+
28+
var provider = new MemcachedCacheProvider(
29+
options.Host,
30+
options.Username,
31+
options.Password,
32+
options.Protocal,
33+
options.AuthenticationType,
34+
options.Expiry);
35+
36+
source.UseCachingProvider(provider);
37+
38+
return source;
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)