Skip to content

Commit 552c6b5

Browse files
authored
Merge pull request #40 from cnblogs/add-set-api
Add Set and SetAsync api
2 parents 0f4177c + 60d9f70 commit 552c6b5

File tree

4 files changed

+52
-25
lines changed

4 files changed

+52
-25
lines changed

Enyim.Caching/Enyim.Caching.csproj

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

33
<PropertyGroup>
44
<Description>EnyimMemcachedCore is a Memcached client library for .NET Core. Usage: Add services.AddEnyimMemcached(...) and app.UseEnyimMemcached() in Startup. Add IMemcachedClient into constructor.</Description>
5-
<VersionPrefix>2.1.0</VersionPrefix>
5+
<VersionPrefix>2.1.0.1</VersionPrefix>
66
<Authors>cnblogs.com</Authors>
77
<TargetFramework>netstandard2.0</TargetFramework>
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

Enyim.Caching/IMemcachedClient.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public interface IMemcachedClient : IDisposable
1111
void Add(string key, object value, int cacheSeconds);
1212
Task AddAsync(string key, object value, int cacheSeconds);
1313

14+
void Set(string key, object value, int cacheSeconds);
15+
Task SetAsync(string key, object value, int cacheSeconds);
16+
1417
Task<IGetOperationResult<T>> GetAsync<T>(string key);
1518
Task<T> GetValueAsync<T>(string key);
1619
object Get(string key);

Enyim.Caching/MemcachedClient.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ public async Task AddAsync(string key, object value, int cacheSeconds)
9898
await StoreAsync(StoreMode.Add, key, value, new TimeSpan(0, 0, cacheSeconds));
9999
}
100100

101+
public void Set(string key, object value, int cacheSeconds)
102+
{
103+
Store(StoreMode.Set, key, value, new TimeSpan(0, 0, cacheSeconds));
104+
}
105+
106+
public async Task SetAsync(string key, object value, int cacheSeconds)
107+
{
108+
await StoreAsync(StoreMode.Set, key, value, new TimeSpan(0, 0, cacheSeconds));
109+
}
110+
101111
/// <summary>
102112
/// Retrieves the specified item from the cache.
103113
/// </summary>

Enyim.Caching/NullMemcachedClient.cs

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Net;
45
using System.Text;
56
using System.Threading.Tasks;
67
using Enyim.Caching.Memcached;
@@ -40,37 +41,37 @@ public CasResult<bool> Cas(StoreMode mode, string key, object value, TimeSpan va
4041

4142
public CasResult<bool> Cas(StoreMode mode, string key, object value, DateTime expiresAt, ulong cas)
4243
{
43-
throw new NotImplementedException();
44+
return new CasResult<bool>();
4445
}
4546

4647
public ulong Decrement(string key, ulong defaultValue, ulong delta)
4748
{
48-
throw new NotImplementedException();
49+
return default(ulong);
4950
}
5051

5152
public ulong Decrement(string key, ulong defaultValue, ulong delta, TimeSpan validFor)
5253
{
53-
throw new NotImplementedException();
54+
return default(ulong);
5455
}
5556

5657
public CasResult<ulong> Decrement(string key, ulong defaultValue, ulong delta, ulong cas)
5758
{
58-
throw new NotImplementedException();
59+
return new CasResult<ulong>();
5960
}
6061

6162
public ulong Decrement(string key, ulong defaultValue, ulong delta, DateTime expiresAt)
6263
{
63-
throw new NotImplementedException();
64+
return default(ulong);
6465
}
6566

6667
public CasResult<ulong> Decrement(string key, ulong defaultValue, ulong delta, TimeSpan validFor, ulong cas)
6768
{
68-
throw new NotImplementedException();
69+
return new CasResult<ulong>();
6970
}
7071

7172
public CasResult<ulong> Decrement(string key, ulong defaultValue, ulong delta, DateTime expiresAt, ulong cas)
7273
{
73-
throw new NotImplementedException();
74+
return new CasResult<ulong>();
7475
}
7576

7677
public void Dispose()
@@ -118,72 +119,72 @@ public async Task<T> GetValueAsync<T>(string key)
118119

119120
public IDictionary<string, CasResult<object>> GetWithCas(IEnumerable<string> keys)
120121
{
121-
throw new NotImplementedException();
122+
return new Dictionary<string, CasResult<object>>();
122123
}
123124

124125
public CasResult<object> GetWithCas(string key)
125126
{
126-
throw new NotImplementedException();
127+
return new CasResult<object>();
127128
}
128129

129130
public CasResult<T> GetWithCas<T>(string key)
130131
{
131-
throw new NotImplementedException();
132+
return new CasResult<T>();
132133
}
133134

134135
public ulong Increment(string key, ulong defaultValue, ulong delta)
135136
{
136-
throw new NotImplementedException();
137+
return default(ulong);
137138
}
138139

139140
public ulong Increment(string key, ulong defaultValue, ulong delta, TimeSpan validFor)
140141
{
141-
throw new NotImplementedException();
142+
return default(ulong);
142143
}
143144

144145
public CasResult<ulong> Increment(string key, ulong defaultValue, ulong delta, ulong cas)
145146
{
146-
throw new NotImplementedException();
147+
return new CasResult<ulong>();
147148
}
148149

149150
public ulong Increment(string key, ulong defaultValue, ulong delta, DateTime expiresAt)
150151
{
151-
throw new NotImplementedException();
152+
return default(ulong);
152153
}
153154

154155
public CasResult<ulong> Increment(string key, ulong defaultValue, ulong delta, TimeSpan validFor, ulong cas)
155156
{
156-
throw new NotImplementedException();
157+
return new CasResult<ulong>();
157158
}
158159

159160
public CasResult<ulong> Increment(string key, ulong defaultValue, ulong delta, DateTime expiresAt, ulong cas)
160161
{
161-
throw new NotImplementedException();
162+
return new CasResult<ulong>();
162163
}
163164

164165
public bool Prepend(string key, ArraySegment<byte> data)
165166
{
166-
throw new NotImplementedException();
167+
return false;
167168
}
168169

169170
public CasResult<bool> Prepend(string key, ulong cas, ArraySegment<byte> data)
170171
{
171-
throw new NotImplementedException();
172+
return new CasResult<bool>();
172173
}
173174

174175
public bool Remove(string key)
175176
{
176177
return true;
177178
}
178179

179-
public async Task<bool> RemoveAsync(string key)
180+
public Task<bool> RemoveAsync(string key)
180181
{
181-
return true;
182+
return Task.FromResult<bool>(false);
182183
}
183184

184185
public ServerStats Stats()
185186
{
186-
throw new NotImplementedException();
187+
return new ServerStats(new Dictionary<EndPoint, Dictionary<string, string>>());
187188
}
188189

189190
public ServerStats Stats(string type)
@@ -218,20 +219,33 @@ public bool Store(StoreMode mode, string key, object value, DateTime expiresAt)
218219

219220
public bool TryGet(string key, out object value)
220221
{
221-
throw new NotImplementedException();
222+
value = null;
223+
return false;
222224
}
223225

224226
public bool TryGetWithCas(string key, out CasResult<object> value)
225227
{
226-
throw new NotImplementedException();
228+
value = new CasResult<object>();
229+
return false;
227230
}
228231

229232
public void Add(string key, object value, int cacheSeconds)
230233
{
231234
}
232235

233-
public async Task AddAsync(string key, object value, int cacheSeconds)
236+
public Task AddAsync(string key, object value, int cacheSeconds)
237+
{
238+
return Task.CompletedTask;
239+
}
240+
241+
public void Set(string key, object value, int cacheSeconds)
242+
{
243+
244+
}
245+
246+
public Task SetAsync(string key, object value, int cacheSeconds)
234247
{
248+
return Task.CompletedTask;
235249
}
236250
}
237251
}

0 commit comments

Comments
 (0)