Enyim Memcached client does not work with passed expiration parameter

When using the Emyim memcached client to store expired data, I believe that it does not work. Can anyone help?

In my test code, I save the date with the expiration of 10 minutes, and I try to get it from the cache immediately, but got a null object.

Enyim.Caching.MemcachedClient client = new Enyim.Caching.MemcachedClient(); client.Store(Enyim.Caching.Memcached.StoreMode.Set, "one", 1, new TimeSpan(0, 10, 0)); object obj; client.TryGet("one", out obj); // obj == null Assert.AreNotEqual(null, obj); // this will fail 
+3
source share
6 answers

I'm not sure if you are vague with your example or if you are really using an object type, but I had the same problem using custom objects. Integers, strings, etc. Will work fine, but my custom object was always NULL as soon as I put it in the cache. Turns out I didn't have the Serializable attribute on my object. As soon as I put this down, everything worked as expected.

+3
source

Hyacinthus is quite accurate in its question, the answers are somewhat irrelevant. I have the same problem ONLY when setting the expiration, either in Timespan or as DateTime.

There is also a problem for this in Enyim github https://github.com/enyim/EnyimMemcached/issues/110

I have a fixed version on my codebase, but it is deprecated. I will try to find a fix and come back to this, and send a stretch request to Enyim when I find the time.

EDIT: I also found this on github.

I can confirm that this does not happen with a different memcached server assembly. I think this is a mistake with this particular assembly: Build with this problem: http://www.urielkatz.com/archive/detail/memcached-64-bit-windows Build WITHOUT this problem: http: //blog.elijaa. org / index.php? post / 2010/08/25 / Memcached-1.4.5-for-Windows

Please note to check the version of the server you are using? My initial comment is still worth it, as I run tests using two different DLLs, and the modified one works as long as the one that comes with CouchBase fails.

+2
source

Please check your server.

1.Use MemCacheD Manager

or

2.Use telnet 127.0.0.1 11211 (changing your server settings)

and enter: stats

It will show your statistics.

See the "stat" item.

The second format you have to convert is

Just you can compare with "1262517674",

If it is less than "1262517674", your memcached server is too old.

Please update or change memcached version.

Otherwise, just change the memcached version

+2
source

The answer is that a 64-bit version of memcached (windows) 1.4.4 is found in this version. If this suits your needs, you can try 1.4.4 32-bit version for Windows, or you can try to find another 64-bit compiled version. This problem also took a whole day, and I finally installed "1.4.4 32-bit version" and alt, everything works fine with 1.4.4. 32 bit

+1
source

Creating a memcached client object is an expensive operation, so try to create it at application startup and reuse this object.

This is how I initiate the MemcachedClient object and access the Membese Build using the Enyim client.

 public class MemcachedManager { protected static MemcachedClient mc = null; public MemcachedManager() { if (mc == null) initMemCached(); } private void initMemCached() { MemcachedClientConfiguration config = new MemcachedClientConfiguration(); string ipstr = "192.168.1.1;192.168.1.2"; // List of Memcaced nodes string[] ips = ipstr.Split(';'); foreach (string ip in ips) { config.Servers.Add(new IPEndPoint(IPAddress.Parse(ip), 11211)); } config.Protocol = MemcachedProtocol.Binary; mc = new MemcachedClient(config); } public void setWithTimeOut(string key, string value, int minutes) { mc.Store(Enyim.Caching.Memcached.StoreMode.Set, key, value, TimeSpan.FromMinutes(minutes)); } public string getString(string key) { return (string)mc.Get(key); } public void setString(string key, string value) { mc.Store(Enyim.Caching.Memcached.StoreMode.Set, key, value); } } 
0
source

you need to get a single first.

eg:

 using System; using Enyim.Caching; using Enyim.Caching.Memcached; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace UnitTestProject1 { [TestClass] public class UnitTest1 { [TestMethod] public void TestMethod1() { MemcachedClient client = MemcachedManager.Instance;//new MemcachedClient(); client.Store(StoreMode.Set, "b", "bb", new TimeSpan(1, 1, 300)); var x = client.Get("b"); client.Store(StoreMode.Set, "a", "aa"); var y = client.Get("a"); client.Store(StoreMode.Set, "c", "cc", DateTime.Now.AddSeconds(300)); var z = client.Get("c"); client.Store(StoreMode.Set, "c", "ccc"); var t = client.Get("c"); Console.WriteLine("{0},{1},{2}",x,y,z); } } public static class MemcachedManager { private readonly static MemcachedClient _instance; static MemcachedManager() { _instance = new MemcachedClient(); } public static MemcachedClient Instance { get { return _instance; } } } } 
0
source

All Articles