|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Text; |
| 4 | +using System.Threading.Tasks; |
| 5 | +using Enyim.Caching.Configuration; |
| 6 | +using Enyim.Caching.Memcached; |
| 7 | +using Enyim.Caching.Memcached.Results; |
| 8 | +using Microsoft.Extensions.Logging; |
| 9 | + |
| 10 | +namespace Enyim.Caching |
| 11 | +{ |
| 12 | + public class MemcachedClient<T> : IMemcachedClient<T> |
| 13 | + { |
| 14 | + private readonly IMemcachedClient _memcachedClient; |
| 15 | + |
| 16 | + public event Action<IMemcachedNode> NodeFailed; |
| 17 | + |
| 18 | + public MemcachedClient(ILoggerFactory loggerFactory, IMemcachedClientConfiguration configuration) |
| 19 | + { |
| 20 | + _memcachedClient = new MemcachedClient(loggerFactory, configuration); |
| 21 | + } |
| 22 | + |
| 23 | + public bool Add(string key, object value, int cacheSeconds) |
| 24 | + { |
| 25 | + return _memcachedClient.Add(key, value, cacheSeconds); |
| 26 | + } |
| 27 | + |
| 28 | + public Task<bool> AddAsync(string key, object value, int cacheSeconds) |
| 29 | + { |
| 30 | + return _memcachedClient.AddAsync(key, value, cacheSeconds); |
| 31 | + } |
| 32 | + |
| 33 | + public bool Append(string key, ArraySegment<byte> data) |
| 34 | + { |
| 35 | + return _memcachedClient.Append(key, data); |
| 36 | + } |
| 37 | + |
| 38 | + public CasResult<bool> Append(string key, ulong cas, ArraySegment<byte> data) |
| 39 | + { |
| 40 | + return _memcachedClient.Append(key, cas, data); |
| 41 | + } |
| 42 | + |
| 43 | + public CasResult<bool> Cas(StoreMode mode, string key, object value) |
| 44 | + { |
| 45 | + return _memcachedClient.Cas(mode, key, value); |
| 46 | + } |
| 47 | + |
| 48 | + public CasResult<bool> Cas(StoreMode mode, string key, object value, ulong cas) |
| 49 | + { |
| 50 | + return _memcachedClient.Cas(mode, key, value, cas); |
| 51 | + } |
| 52 | + |
| 53 | + public CasResult<bool> Cas(StoreMode mode, string key, object value, DateTime expiresAt, ulong cas) |
| 54 | + { |
| 55 | + return _memcachedClient.Cas(mode, key, value, expiresAt, cas); |
| 56 | + } |
| 57 | + |
| 58 | + public CasResult<bool> Cas(StoreMode mode, string key, object value, TimeSpan validFor, ulong cas) |
| 59 | + { |
| 60 | + return _memcachedClient.Cas(mode, key, value, validFor, cas); |
| 61 | + } |
| 62 | + |
| 63 | + public ulong Decrement(string key, ulong defaultValue, ulong delta) |
| 64 | + { |
| 65 | + return _memcachedClient.Decrement(key, defaultValue, delta); |
| 66 | + } |
| 67 | + |
| 68 | + public ulong Decrement(string key, ulong defaultValue, ulong delta, DateTime expiresAt) |
| 69 | + { |
| 70 | + return _memcachedClient.Decrement(key, defaultValue, delta, expiresAt); |
| 71 | + } |
| 72 | + |
| 73 | + public ulong Decrement(string key, ulong defaultValue, ulong delta, TimeSpan validFor) |
| 74 | + { |
| 75 | + return _memcachedClient.Decrement(key, defaultValue, delta, validFor); |
| 76 | + } |
| 77 | + |
| 78 | + public CasResult<ulong> Decrement(string key, ulong defaultValue, ulong delta, ulong cas) |
| 79 | + { |
| 80 | + return _memcachedClient.Decrement(key, defaultValue, delta, cas); |
| 81 | + } |
| 82 | + |
| 83 | + public CasResult<ulong> Decrement(string key, ulong defaultValue, ulong delta, DateTime expiresAt, ulong cas) |
| 84 | + { |
| 85 | + return _memcachedClient.Decrement(key, defaultValue, delta, expiresAt, cas); |
| 86 | + } |
| 87 | + |
| 88 | + public CasResult<ulong> Decrement(string key, ulong defaultValue, ulong delta, TimeSpan validFor, ulong cas) |
| 89 | + { |
| 90 | + return _memcachedClient.Decrement(key, defaultValue, delta, validFor, cas); |
| 91 | + } |
| 92 | + |
| 93 | + public void Dispose() |
| 94 | + { |
| 95 | + _memcachedClient.Dispose(); |
| 96 | + } |
| 97 | + |
| 98 | + public void FlushAll() |
| 99 | + { |
| 100 | + _memcachedClient.FlushAll(); |
| 101 | + } |
| 102 | + |
| 103 | + public Task FlushAllAsync() |
| 104 | + { |
| 105 | + return _memcachedClient.FlushAllAsync(); |
| 106 | + } |
| 107 | + |
| 108 | + public object Get(string key) |
| 109 | + { |
| 110 | + return _memcachedClient.Get(key); |
| 111 | + } |
| 112 | + |
| 113 | + public T1 Get<T1>(string key) |
| 114 | + { |
| 115 | + return _memcachedClient.Get<T1>(key); |
| 116 | + } |
| 117 | + |
| 118 | + public IDictionary<string, T1> Get<T1>(IEnumerable<string> keys) |
| 119 | + { |
| 120 | + return _memcachedClient.Get<T1>(keys); |
| 121 | + } |
| 122 | + |
| 123 | + public Task<IGetOperationResult<T1>> GetAsync<T1>(string key) |
| 124 | + { |
| 125 | + return _memcachedClient.GetAsync<T1>(key); |
| 126 | + } |
| 127 | + |
| 128 | + public Task<IDictionary<string, T1>> GetAsync<T1>(IEnumerable<string> keys) |
| 129 | + { |
| 130 | + return _memcachedClient.GetAsync<T1>(keys); |
| 131 | + } |
| 132 | + |
| 133 | + public Task<T1> GetValueAsync<T1>(string key) |
| 134 | + { |
| 135 | + return _memcachedClient.GetValueAsync<T1>(key); |
| 136 | + } |
| 137 | + |
| 138 | + public Task<T1> GetValueOrCreateAsync<T1>(string key, int cacheSeconds, Func<Task<T1>> generator) |
| 139 | + { |
| 140 | + return _memcachedClient.GetValueOrCreateAsync<T1>(key, cacheSeconds, generator); |
| 141 | + } |
| 142 | + |
| 143 | + public CasResult<object> GetWithCas(string key) |
| 144 | + { |
| 145 | + return _memcachedClient.GetWithCas(key); |
| 146 | + } |
| 147 | + |
| 148 | + public CasResult<T1> GetWithCas<T1>(string key) |
| 149 | + { |
| 150 | + return _memcachedClient.GetWithCas<T1>(key); |
| 151 | + } |
| 152 | + |
| 153 | + public IDictionary<string, CasResult<object>> GetWithCas(IEnumerable<string> keys) |
| 154 | + { |
| 155 | + return _memcachedClient.GetWithCas(keys); |
| 156 | + } |
| 157 | + |
| 158 | + public Task<IDictionary<string, CasResult<object>>> GetWithCasAsync(IEnumerable<string> keys) |
| 159 | + { |
| 160 | + return _memcachedClient.GetWithCasAsync(keys); |
| 161 | + } |
| 162 | + |
| 163 | + public ulong Increment(string key, ulong defaultValue, ulong delta) |
| 164 | + { |
| 165 | + return _memcachedClient.Increment(key, defaultValue, delta); |
| 166 | + } |
| 167 | + |
| 168 | + public ulong Increment(string key, ulong defaultValue, ulong delta, DateTime expiresAt) |
| 169 | + { |
| 170 | + return _memcachedClient.Increment(key, defaultValue, delta, expiresAt); |
| 171 | + } |
| 172 | + |
| 173 | + public ulong Increment(string key, ulong defaultValue, ulong delta, TimeSpan validFor) |
| 174 | + { |
| 175 | + return _memcachedClient.Increment(key, defaultValue, delta, validFor); |
| 176 | + } |
| 177 | + |
| 178 | + public CasResult<ulong> Increment(string key, ulong defaultValue, ulong delta, ulong cas) |
| 179 | + { |
| 180 | + return _memcachedClient.Increment(key, defaultValue, delta, cas); |
| 181 | + } |
| 182 | + |
| 183 | + public CasResult<ulong> Increment(string key, ulong defaultValue, ulong delta, DateTime expiresAt, ulong cas) |
| 184 | + { |
| 185 | + return _memcachedClient.Increment(key, defaultValue, delta, expiresAt, cas); |
| 186 | + } |
| 187 | + |
| 188 | + public CasResult<ulong> Increment(string key, ulong defaultValue, ulong delta, TimeSpan validFor, ulong cas) |
| 189 | + { |
| 190 | + return _memcachedClient.Increment(key, defaultValue, delta, validFor, cas); |
| 191 | + } |
| 192 | + |
| 193 | + public bool Prepend(string key, ArraySegment<byte> data) |
| 194 | + { |
| 195 | + return _memcachedClient.Prepend(key, data); |
| 196 | + } |
| 197 | + |
| 198 | + public CasResult<bool> Prepend(string key, ulong cas, ArraySegment<byte> data) |
| 199 | + { |
| 200 | + return _memcachedClient.Prepend(key, cas, data); |
| 201 | + } |
| 202 | + |
| 203 | + public bool Remove(string key) |
| 204 | + { |
| 205 | + return _memcachedClient.Remove(key); |
| 206 | + } |
| 207 | + |
| 208 | + public Task<bool> RemoveAsync(string key) |
| 209 | + { |
| 210 | + return _memcachedClient.RemoveAsync(key); |
| 211 | + } |
| 212 | + |
| 213 | + public bool Replace(string key, object value, int cacheSeconds) |
| 214 | + { |
| 215 | + return _memcachedClient.Replace(key, value, cacheSeconds); |
| 216 | + } |
| 217 | + |
| 218 | + public Task<bool> ReplaceAsync(string key, object value, int cacheSeconds) |
| 219 | + { |
| 220 | + return _memcachedClient.ReplaceAsync(key, value, cacheSeconds); |
| 221 | + } |
| 222 | + |
| 223 | + public bool Set(string key, object value, int cacheSeconds) |
| 224 | + { |
| 225 | + return _memcachedClient.Set(key, value, cacheSeconds); |
| 226 | + } |
| 227 | + |
| 228 | + public Task<bool> SetAsync(string key, object value, int cacheSeconds) |
| 229 | + { |
| 230 | + return _memcachedClient.SetAsync(key, value, cacheSeconds); |
| 231 | + } |
| 232 | + |
| 233 | + public ServerStats Stats() |
| 234 | + { |
| 235 | + return _memcachedClient.Stats(); |
| 236 | + } |
| 237 | + |
| 238 | + public ServerStats Stats(string type) |
| 239 | + { |
| 240 | + return _memcachedClient.Stats(type); |
| 241 | + } |
| 242 | + |
| 243 | + public bool Store(StoreMode mode, string key, object value) |
| 244 | + { |
| 245 | + return _memcachedClient.Store(mode, key, value); |
| 246 | + } |
| 247 | + |
| 248 | + public bool Store(StoreMode mode, string key, object value, DateTime expiresAt) |
| 249 | + { |
| 250 | + return _memcachedClient.Store(mode, key, value, expiresAt); |
| 251 | + } |
| 252 | + |
| 253 | + public bool Store(StoreMode mode, string key, object value, TimeSpan validFor) |
| 254 | + { |
| 255 | + return _memcachedClient.Store(mode, key, value, validFor); |
| 256 | + } |
| 257 | + |
| 258 | + public Task<bool> StoreAsync(StoreMode mode, string key, object value, DateTime expiresAt) |
| 259 | + { |
| 260 | + return _memcachedClient.StoreAsync(mode, key, value, expiresAt); |
| 261 | + } |
| 262 | + |
| 263 | + public Task<bool> StoreAsync(StoreMode mode, string key, object value, TimeSpan validFor) |
| 264 | + { |
| 265 | + return _memcachedClient.StoreAsync(mode, key, value, validFor); |
| 266 | + } |
| 267 | + |
| 268 | + public Task<IOperationResult> TouchAsync(string key, DateTime expiresAt) |
| 269 | + { |
| 270 | + return _memcachedClient.TouchAsync(key, expiresAt); |
| 271 | + } |
| 272 | + |
| 273 | + public Task<IOperationResult> TouchAsync(string key, TimeSpan validFor) |
| 274 | + { |
| 275 | + return _memcachedClient.TouchAsync(key, validFor); |
| 276 | + } |
| 277 | + |
| 278 | + public bool TryGet(string key, out object value) |
| 279 | + { |
| 280 | + return _memcachedClient.TryGet(key, out value); |
| 281 | + } |
| 282 | + |
| 283 | + public bool TryGetWithCas(string key, out CasResult<object> value) |
| 284 | + { |
| 285 | + return _memcachedClient.TryGetWithCas(key, out value); |
| 286 | + } |
| 287 | + } |
| 288 | +} |
0 commit comments