Example #1
0
        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);
            }
        }
Example #2
0
        public ICacheProvider <string, testObj> GetProvider()
        {
            MemcachedCluster cls = new MemcachedCluster("localhost");

            cls.Start();
            return(new MemcachedCacheProvider <testObj>(cls));
        }
Example #3
0
        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();
        }
Example #4
0
        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);
        }
Example #5
0
 public MemcachedCacheProvider(MemcachedCluster cluster)
 {
     this._cluster = cluster;
 }