Enyim Memcached客户端无法与传递的到期参数一起使用 [英] Enyim Memcached client doesn't work with expiration parameter passed

查看:82
本文介绍了Enyim Memcached客户端无法与传递的到期参数一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用Enyim memcached客户端存储具有过期时间的数据时,我发现它不起作用. 有人可以帮忙吗?

when using Enyim memcached client to store data with a expire timespan, i find that it doesn't work. Could anyone help?

在我的测试代码中,我将日期与10分钟的有效时间存储在一起,我尝试立即从缓存中获取日期,但得到一个空对象.

In my test code, I store the date with 10 minutes expiration time, and i try to get it from 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

推荐答案

我不确定您的示例是否含糊不清,或者您是否确实在使用对象类型,但是使用自定义对象也遇到了相同的问题.整数,字符串等可以正常工作,但是一旦将其放入缓存,我的自定义对象始终为NULL.原来我的对象上没有Seri​​alizable属性.一旦我把它放到那里,一切都会按预期进行.

I'm not sure if you're being vague w/ your example or if you really are using an object type but I had the same problem using custom objects. Integers, strings, etc. would 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. Once I put that on there everything worked as expected.

这篇关于Enyim Memcached客户端无法与传递的到期参数一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆