How does PHP cache to memcache based on URL parameters?
$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 ());//Take the current number of minutes
$key = ' rate '. $minute _now;
if (Memcache_get ($link, $key) = = null)
{
Memcache_set ($link, $key, $temp, 0,//set);
Note that 20 here is the cache expiration time, 60 seconds is 1 minutes
}
$re = Memcache_get ($link, $key, $temp);
Var_dump ($re);
if ($re >ratemax)
{
}else{
Memcache_increment ($link, $key);
}
?>
Each refresh is changed without a cache
After caching
Demo Address http://niaochen006.sinaapp.com/zq.php
Cache time 20 seconds change once
What I want to achieve is
Http://niaochen006.sinaapp.com/zq.php?=AABB
Http://niaochen006.sinaapp.com/zq.php?=BBCC
http://niaochen006.sinaapp.com/zq.php?=*****
Cache different pages for each URL parameter
How to achieve it?
------Solution--------------------
Transform $key
You're now.
$key = ' rate '. $minute _now;
It's associated with time.
Change it to $url related.