Home > Backend Development > PHP Tutorial > php如何根据url参数缓存到memcache?

php如何根据url参数缓存到memcache?

WBOY
Release: 2016-06-23 14:13:30
Original
835 people have browsed it

<?php$file=file('link.txt');$max=count($file)-1;for($i=0;$i<5;$i++){	$index=mt_rand(0,$max);	$temp= "".trim($file["$index"])."";}$link = memcache_init();$minute_now = date('i',time());//取当前的分钟数$key = 'rate'.$minute_now;if(memcache_get($link,$key) == null){        memcache_set($link, $key, $temp, 0, 20);//set        //注意此处的20是缓存过期时间,60秒为1分钟     }$re = memcache_get($link,$key,$temp);var_dump($re);if($re>RATEMAX){}else{        memcache_increment($link,$key);} ?>
Copy after login

没有缓存之前是每次刷新都是变的
缓存之后
演示地址http://niaochen006.sinaapp.com/zq.php
缓存时间 20秒变一次

我想要实现的是 
http://niaochen006.sinaapp.com/zq.php?=AABB
http://niaochen006.sinaapp.com/zq.php?=BBCC
http://niaochen006.sinaapp.com/zq.php?=*****

每个URL参数不同就缓存不同的页面
如何实现呢?


回复讨论(解决方案)

改造一下 $key 
你现在的
$key = 'rate'.$minute_now;
是与时间相联系的

改成与 $url 相关的就是了

楼上说的很对
xuzuning已经5星了,果然牛啊

支持一下,最近我也关注 缓存!!!

我也来mark 一下  最近学缓存

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template