Skip to content

Commit 1312709

Browse files
(GH-613) Re-factor memcached caching provider
1 parent 9115e11 commit 1312709

File tree

3 files changed

+225
-298
lines changed

3 files changed

+225
-298
lines changed

src/DotNetToolkit.Repository.Caching.Memcached/MemcachedCache.cs

Lines changed: 0 additions & 151 deletions
This file was deleted.
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
namespace DotNetToolkit.Repository.Caching.Memcached
2+
{
3+
using Enyim.Caching.Memcached;
4+
using JetBrains.Annotations;
5+
using System;
6+
using Utility;
7+
8+
/// <summary>
9+
/// The options to be used by the memcached caching provider.
10+
/// </summary>
11+
public class MemcachedCacheOptions
12+
{
13+
private string _host;
14+
private string _username;
15+
private string _password;
16+
private MemcachedProtocol _protocal;
17+
private Type _authType;
18+
private TimeSpan? _expiry;
19+
20+
/// <summary>
21+
/// Gets the host.
22+
/// </summary>
23+
public string Host { get { return _host; } }
24+
25+
/// <summary>
26+
/// Gets the username.
27+
/// </summary>
28+
public string Username { get { return _username; } }
29+
30+
/// <summary>
31+
/// Gets the password.
32+
/// </summary>
33+
public string Password { get { return _password; } }
34+
35+
/// <summary>
36+
/// Gets the protocal.
37+
/// </summary>
38+
public MemcachedProtocol Protocal { get { return _protocal; } }
39+
40+
/// <summary>
41+
/// Gets the authentication type.
42+
/// </summary>
43+
public Type AuthenticationType { get { return _authType; } }
44+
45+
/// <summary>
46+
/// Gets the expiration time.
47+
/// </summary>
48+
public TimeSpan? Expiry { get { return _expiry; } }
49+
50+
/// <summary>
51+
/// Adds the giving password to the options.
52+
/// </summary>
53+
/// <param name="username">The user name to be added.</param>
54+
public MemcachedCacheOptions WithUserName([NotNull] string username)
55+
{
56+
_username = Guard.NotEmpty(username, nameof(username));
57+
58+
return this;
59+
}
60+
61+
/// <summary>
62+
/// Adds the giving password to the options.
63+
/// </summary>
64+
/// <param name="password">The password to be added.</param>
65+
public MemcachedCacheOptions WithPassword([NotNull] string password)
66+
{
67+
_password = Guard.NotEmpty(password, nameof(password));
68+
69+
return this;
70+
}
71+
72+
/// <summary>
73+
/// Adds the giving endpoint to the options.
74+
/// </summary>
75+
/// <param name="host">The host name to be added.</param>
76+
/// <param name="port">The port to be added.</param>
77+
public MemcachedCacheOptions WithEndPoint([NotNull] string host, int port)
78+
{
79+
Guard.NotEmpty(host, nameof(host));
80+
81+
_host = string.Format("{0}:{1}", host, port);
82+
83+
return this;
84+
}
85+
86+
/// <summary>
87+
/// Adds the giving endpoint to the options.
88+
/// </summary>
89+
/// <param name="hostAndPort">The host and port to be added.</param>
90+
public MemcachedCacheOptions WithEndPoint([NotNull] string hostAndPort)
91+
{
92+
_host = Guard.NotEmpty(hostAndPort, nameof(hostAndPort));
93+
94+
return this;
95+
}
96+
97+
/// <summary>
98+
/// Adds the giving protocal to the options.
99+
/// </summary>
100+
/// <param name="protocal">The protocal to be added.</param>
101+
public MemcachedCacheOptions WithProtocal([NotNull] MemcachedProtocol protocal)
102+
{
103+
_protocal = Guard.NotNull(protocal, nameof(protocal));
104+
105+
return this;
106+
}
107+
108+
/// <summary>
109+
/// Adds the giving authentication type to the options.
110+
/// </summary>
111+
public MemcachedCacheOptions WithAuthType<T>()
112+
{
113+
_authType = typeof(T);
114+
115+
return this;
116+
}
117+
118+
/// <summary>
119+
/// Adds the giving caching expiration time to the options.
120+
/// </summary>
121+
/// <param name="expiry">The caching expiration time to be added.</param>
122+
public MemcachedCacheOptions WithExpiry([NotNull] TimeSpan expiry)
123+
{
124+
_expiry = Guard.NotNull(expiry, nameof(expiry));
125+
126+
return this;
127+
}
128+
}
129+
}

0 commit comments

Comments
 (0)