How does php Cache data to memcache based on url parameters?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.