Search code examples
c#amazon-web-servicesmemcachedamazon-elasticacheenyim.caching

AWS C# lambda using Memcached (EnyimMemcached), store always fails


In AWS I have setup a small memcached node in my VPC in a private subnet. My lambda is in the same VPC and private subnet.

My lambda runs the EnyimMemcached code without exceptions.

When I look in CloudWatch there is connections to my memcache node when the lambda is executed, and it also shows bytes written, but "Cache items bytes used" stays at 0 and the store command returns "False".

My Get requests are also shown in Cloudwatch, so it seems there is a connection to the node. My get is always a miss and that makes sense since the store is not successfull.

This is how I have setup memcache while testing. I hope someone can point me to what I am doing wrong, because I have been stuck for a while trying to figure this out.

var loggerFactory = new LoggerFactory();
ILogger logger = loggerFactory.CreateLogger<ValuesController>();

var memcacheOptions = new MemcachedClientOptions();

var config = new MemcachedClientConfiguration(loggerFactory, memcacheOptions);
config.Protocol = MemcachedProtocol.Binary;

var mc = new MemcachedClient(loggerFactory, config);

bool done = mc.Store(StoreMode.Set, "foo", "bar", DateTime.Now.AddMinutes(5));

Thanks


Solution

  • After doing the following changes it started working:

    var memcacheOptions = new MemcachedClientOptions();
    memcacheOptions.Protocol = MemcachedProtocol.Binary;
    
    var config = new MemcachedClientConfiguration(loggerFactory, memcacheOptions);
    config.AddServer("memcache_server_address:port");
    

    Now I am working on finding the right setup of the address in the ConfigureServices in the Startup.