public MemCached(IOptions <MemCachedOptions> options, ILogger <MemCached> logger) { _logger = logger; try { MemcachedCluster cluster; if (!string.IsNullOrWhiteSpace(options.Value.host)) { cluster = new MemcachedCluster($"{options.Value.host}:{options.Value.port}"); } else { cluster = new MemcachedCluster("localhost:11212"); } cluster.Start(); _memcache = cluster.GetClient(); } catch (Exception ex) { _logger.LogError(new EventId(ex.HResult), ex, ex.Message); } }
public ICacheProvider <string, testObj> GetProvider() { MemcachedCluster cls = new MemcachedCluster("localhost"); cls.Start(); return(new MemcachedCacheProvider <testObj>(cls)); }
static async Task Main(string[] args) { // connect to a list of memcached servers var cluster = new MemcachedCluster("localhost,localhost:11212,localhost:11213"); // this is mandatory cluster.Start(); var client = cluster.GetClient(); await client.SetAsync("hello", new { hello = "world" }); // more work // stop the cluster cluster.Dispose(); }
private async Task RunEnyim() { using var _enyim = new MemcachedCluster("10.0.0.21:11211"); _enyim.Start(); var _enyimClient = _enyim.GetClient(); var list = new List <Task>(); for (var i = 0; i < Threads; i++) { list.Add(Task.Run(async() => { await _enyimClient.SetAsync(Key, Value); foreach (var batch in Enumerable.Range(0, Iterations).Batch(200)) { await Task.WhenAll(batch.Select(x => _enyimClient.GetAsync(Key))); } })); } await Task.WhenAll(list); }
public MemcachedCacheProvider(MemcachedCluster cluster) { this._cluster = cluster; }