最近项目中使用到了Memcached,而客户端选择了XMemcached ,在设置过期时间时,因对Memcached 不熟悉,将expire 设置为1000000000,本意表示尽量长的时间不要过期,但在测试时发现,memcachedClient.set(key,exp,value)结果返回true,即代表该项已成功存入缓存,但当调用memcachedClient.get(key)时始终返回为null,起初以为key的生成策略有误,后来当把exp填了个1000时,Memcached的set 和 get方法均返回true,看来问题出在expire,所以查了下文档,发现Memcached默认expire为0即代表永不过期,而这个过期时间最长为30天=
30*24*60*60 = 2592000秒,所以又将expire配置为2592000秒,发现正常执行,为了测试Memcached是否为最长30天,又将该值加了1变成2592001,此时出现了和开始一样的错误,set返回 true,但get返回为null,这样应该映证了30长最长时间的猜想。而这个时间应该是Memcached本身设置的,经过查找发现Memcached源码memcached.c里边有如下代码。注意第一行 #define REALTIME_MAXDELTA 60*60*24*30 即为30天。

  1. #define REALTIME_MAXDELTA 60*60*24*30
  2. /*
  3. * given time value that's either unix time or delta from current unix time, return
  4. * unix time. Use the fact that delta can't exceed one month (and real time value can't
  5. * be that low).
  6. */
  7. static rel_time_t realtime(const time_t exptime) {
  8. /* no. of seconds in 30 days - largest possible delta exptime */
  9. if (exptime == 0) return 0; /* 0 means never expire */
  10. if (exptime > REALTIME_MAXDELTA) {
  11. /* if item expiration is at/before the server started, give it an
  12. expiration time of 1 second after the server started.
  13. (because 0 means don't expire).  without this, we'd
  14. underflow and wrap around to some large value way in the
  15. future, effectively making items expiring in the past
  16. really expiring never */
  17. if (exptime <= process_started)
  18. return (rel_time_t)1;
  19. return (rel_time_t)(exptime - process_started);
  20. } else {
  21. return (rel_time_t)(exptime + current_time);
  22. }
  23. }

XMemcached是一个新java memcached client。Memcached 是一个高性能的分布式内存对象的key-value缓存系统,用于动态Web应用以减轻数据库负载,

现在也有很多人将它作为内存式数据库在使用,memcached通过它的自定义协议与客户端交互,而XMemcached就是它的一个java客户端实现。

关于XMemcached详细说明,参考.htmXMemcached简介

xmemcached过期时间的更多相关文章

  1. [ASP.NET] 如果将缓存“滑动过期时间”设置为1秒会怎样?

    今天编写了一个采用ASP.NET Caching的组件,在为它编写Unit Test的过程中发现了一个有趣的问题,接下来我通过一个简单的实例说明这个问题.我们在一个控制台应用中编写了如下一段程序,这个 ...

  2. ahjesus在asp.net中还可以通过设置HttpCookie对象的过期时间为DateTime.MinValue来指定此Cookies为跟随浏览器生效

    ahjesus在asp.net中还可以通过设置HttpCookie对象的过期时间为DateTime.MinValue来指定此Cookies为跟随浏览器生效

  3. C# Cache 设定缓存过期时间方法 绝对过期时间 和 相对过期时间(即:访问激活后不过期)

    摘自: http://www.cnblogs.com/zj1111184556/p/3493840.html 1. 设定绝对过期时间 /// <summary> /// 设定绝对的过期时间 ...

  4. memcached的key,value,过期时间的限制

    1.   key值最大长度? memcached的key的最大长度是250个字符,是memcached服务端的限制. 如果您使用的客户端支持"key的前缀"或类似特性,那么key( ...

  5. redis中的key设置过期时间

    EXPIRE key seconds 为给定  key  设置生存时间,当  key  过期时(生存时间为  0  ),它会被自动删除. 在 Redis 中,带有生存时间的  key  被称为『易失的 ...

  6. session过期时间

    在一般系统登录后,都会设置一个当前session失效的时间,以确保在用户没有使用系统一定时间后,自动退出登录,销毁session. 具体设置很简单: 在主页面或者公共页面中加入:session.set ...

  7. asp.net web.config 设置Session过期时间

    在Asp.net中,可以有四处设置Session的过期时间:(原文作者:望月狼地址:http://www.cnblogs.com/wangyuelang0526/) 一.全局网站(即服务器)级 IIS ...

  8. Node.js刷新session过期时间

    在Node.js中,我们通常使用express-session这个包来使用和管理session,保存服务端和客户端浏览器之间的会话状态.那如何才能实现当用户刷新当前页面或者点击页面上的按钮时重新刷新s ...

  9. CentOS6设置密码过期时间

    #密码过期时间180天chage -M 180 rootchage -l rootchage -M 180 gwchage -l gw

随机推荐

  1. .NET httpClient Post请求,GET请求方法

    1.后端是WebAPI,POST请求,修饰符是[FromBody]的字符串,[FromBody]修饰的时候数据是来自body部分,而不是来自url部分,所以后端取值会自动映射出数据,比如后端是这样的, ...

  2. WebSocket的简单实现&jsp

    创建一个web项目 导入依赖: <?xml version="1.0" encoding="UTF-8"?> <project xmlns=& ...

  3. c++ 广度优先搜索

    #include <iostream> using namespace std; ; ; // >=9皆可 struct node//声明图形顶点结构 { int vertex; s ...

  4. 在java中如何根据手机号查询号码归属地

    1.maven项目中配置 <dependency><groupId>com.googlecode.libphonenumber</groupId><artif ...

  5. POJ 3013 SPFA算法,邻接表的使用

    Big Christmas Tree Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 19029   Accepted: 4 ...

  6. SQL基础教程(第2版)第3章 聚合与排序:3-1 对表进行聚合查询

    3-1 对表进行聚合查询 ● 使用聚合函数对表中的列进行计算合计值或者平均值等的汇总操作.● 通常,聚合函数会对NULL以外的对象进行汇总.但是只有COUNT函数例外,使用COUNT(*)可以查出包含 ...

  7. Linux--shell 脚本免密码输入

    参考:https://www.cnblogs.com/lixigang/articles/4849527.html #!/bin/bash ssb=" password=mysql data ...

  8. css3 flex布局详解

    原文链接: http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html?utm_source=tuicool https://www.cnblog ...

  9. go语言实现leetcode-242

    package main import ( "fmt" "reflect" ) func isAnagram(s string, t string) bool ...

  10. h5-localStorage储存的使用

    <!-- localStorage的使用: 1.存储的内容大概20mb 2.不同浏览器不能共享数据,但是在同意浏览器的不同窗口中可以共享数据 3.永久生效,他的数据是储存在硬盘上,并不会随着页面 ...