How does php Cache data to memcache based on url parameters? & Lt ;? Php?file=file('link.txt '); $ max = count ($ file)-1; for ($ I = 0; $ I & lt; 5; $ I ++) {$ index = mt_rand (0, $ max); $ temp = & nbsp php how to cache data to memcache based on url parameters?
Using file1_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 (); // get the current number of minutes
$ Key = 'rate'. $ minute_now;
If (memcache_get ($ link, $ key) = null)
{
Memcache_set ($ link, $ key, $ temp, 0, 20); // set
// Note that 20 indicates the cache expiration time, and 60 seconds indicates 1 minute.
}
$ Re = memcache_get ($ link, $ key, $ temp );
Var_dump ($ re );
If ($ re> RATEMAX)
{
} Else {
Memcache_increment ($ link, $ key );
}
?>
It changes every refresh before there is no cache.
After caching
Demo address http://niaochen006.sinaapp.com/zq.php
Cache time changed once in 20 seconds
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? = *****
Different URL parameters cache different pages
How to implement it?
------ Solution --------------------
Modify $ key
Your current
$ Key = 'rate'. $ minute_now;
Is associated with the time
It is related to $ url.