2

I'm trying to test my AWS Elasticache nodes using Memcached and the Enyim client, however for some reason the expiry time seems to be out by 1 hour.

I've added data using this code:

_client.Store(StoreMode.Set, "testkey", "test", DateTime.Now.AddMinutes(1));

Then I'm attempting to retrieve the data using

var data = _client.Get<string>("testkey");

However this never retrieves the data. If however I change the expiry to 61 minutes from now, it will store the data for 1 minute. I've tried this with TimeSpan rather than DateTime.Now but get the same issue.

I've also outputted DateTime.Now value which is correct, and my AWS region is EU-West which is in the same timezone as the outputted DateTime.Now

andrewm
  • 2,552
  • 5
  • 33
  • 63

2 Answers2

2

It would be safer to use:

_client.Store(StoreMode.Set, "testkey", "test", TimeSpan.FromMinutes(1.0));

This way, you won't have any dependencies to the DateTime and UTC.

Houman
  • 1,381
  • 1
  • 8
  • 10
0

I figured it out myself. I didn't really take UTC into account, and that's what the Elasticache instances use. Therefore to fix my issue I just need to use DateTime.UtcNow rather than DateTime.Now

andrewm
  • 2,552
  • 5
  • 33
  • 63