dtz46697 2013-08-05 10:08
浏览 71

两个键可以指向memcache中的相同数据

I am using PHP and Memcache. I want multiple keys to point to the same data.

$datawallright = $memcache->get('wads'.$wall->getIdwall());

This is how I retrieve the data. If there is no data I make some MySql queries, which take time. Most of the times the key points to unique data. The problem is that sometimes I want more keys to point to the same data.

$memcache->set('wads'.$wall->getIdwall(), $datawallright, false, 3600) or die ("Failed to save data at the server");

If I do this it is going to save the data in memcache which is ok for the unique values, but it is going to store the data multiple times in the other scenario, which is a waste of space in the cache.

So what I want bassicaly is wads1 and wads2 to point to the same data in memcache.

  • 写回答

1条回答 默认 最新

  • duanniwu7730 2013-08-05 18:51
    关注

    No, there is no native way to make memcached share objects between keys.

    If you really need to implement such a thing, you could however implement such a workaround yourself. For example, assume that key hello maps to object world.

    You could make it so that in your codebase, any key that has for value {'alias': N} will make your code perform a memcached lookup for key N. So in this case, you would just store data as follow:

    hello -> world

    hello2 -> {'alias': 'hello'}

    hello3 -> {'alias': 'hello'}

    This is likely a bad pattern to have in your code though; it would be cleaner and easier to maintain if you just always refer to the key that points to the data you want in the first place (and it would save an extra memcached hit every time).

    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划