The Zend cache ID is generated to clear the specified Zend cache page.

Source: Internet
Author: User

/*
*
How to clear '/Zhidao /? Page = 1 & id = 2 'cache.
Zend_loader: loadclass ('m M _ cacheid ');
$ Cacheid = custom_cacheid: makeid ('/Zhidao /? Page = 1 & id = 2', config: $ cacheoptions );
$ Globals ['cache']-> remove ($ cacheid );
*/
Class custom_cacheid
{
Static $ get = NULL;
Static $ post = NULL;
Static $ session = NULL;
Static $ cookie = NULL;
/**
* The cache ID is returned Based on the provided URL and cache options (config: $ cacheoptions in the system ).
* Set $ Param to change the $ _ Get, $ _ post, $ _ cookie, $ _ Session value,
For example:
$ Param = array (
'Post' => array ('id' => 1, 'page' => 1)
);
Set $ _ post to array ('id' => 1, 'page' => 1 ).
Note: The get parameter is automatically obtained based on the URL.
Note: $ URL? The get parameter cannot be incorrect, for example? A = & page = 1; str2arr is just a simple function, which may be different from the PHP analysis method, resulting in failure to obtain the correct ID
*/
Static public function makeid ($ URL, $ activeoptions, $ Param = array ())
{
Foreach ($ Param as $ key => $ value ){
SELF: $ key = $ value;
}
If (strpos ($ URL ,'? ')! = False ){
SELF: $ get = self: str2arr (substr ($ URL, strpos ($ URL ,'? ')));
}
$ TMP = $ URL;
Foreach (Array ('get', 'post', 'session ', 'files', 'cookies') as $ arrayname ){

$ Tmp2 = self: _ makepartialid (
$ Arrayname,
Isset ($ activeoptions ['cache _ with _ '. strtolower ($ arrayname).' _ variables '])? $ Activeoptions ['cache _ with _ '. strtolower ($ arrayname).' _ variables ']: false,
Isset ($ activeoptions ['make _ id_with _ '. strtolower ($ arrayname).' _ variables '])? $ Activeoptions ['make _ id_with _ '. strtolower ($ arrayname).' _ variables ']: True
);
If ($ tmp2 ===false ){
Return false;
}
$ TMP = $ TMP. $ tmp2;
}
Return MD5 ($ TMP );
}

/**
* Make a partial ID depending on options
*
* @ Param string $ arrayname superglobal array name
* @ Param bool $ bool1 if true, cache is still on even if there are some variables in the superglobal Array
* @ Param bool $ bool2 if true, we have to use the content of the superglobal array to make a partial ID
* @ Return mixed | false partial ID (string) or false if the cache shocould have not to be used
*/
Private Static function _ makepartialid ($ arrayname, $ bool1, $ bool2)
{
Switch ($ arrayname ){
Case 'get ':
$ Var =! Empty (Self ::$ get )? SELF: $ get: $ _ Get;
Break;
Case 'post ':
$ Var =! Empty (Self ::$ post )? SELF: $ post: $ _ post;
Break;
Case 'session ':
If (! Empty (SELF: $ session )){
$ Var = self: $ session;
} Else {
If (isset ($ _ Session )){
$ Var = $ _ Session;
} Else {
$ Var = NULL;
}
}
Break;
Case 'cookies ':
If (! Empty (SELF: $ cookie )){
$ Var = self: $ cookie;
} Else {
If (isset ($ _ cookie )){
$ Var =$ _ cookie;
} Else {
$ Var = NULL;
}
}
Break;
Case 'files ':
$ Var = $ _ files;
Break;
Default:
Return false;
}
If ($ bool1 ){
If ($ bool2 ){
Return serialize ($ var );
}
Return '';
}
If (count ($ var)> 0 ){
Echo $ arrayname. '<HR> ';
Return false;
}
Return '';
}
/*
* Convert a string to an array.
For example, input? Page = 1 & id = 1 will return array ('page' => 1, 'id' => 1)
*/
Static function str2arr ($ Str ){
$ STR = preg_replace ("/^ /? /"," ", $ Str );
$ TMP = Split ("&", $ Str );
$ Return = array ();
Foreach ($ TMP as $ t ){
$ String = Split ("=", $ t );
If (count ($ string) = 2 ){
$ Return [$ string [0] = $ string [1];
}
}
Return $ return;
}
}

 

 

Config: $ cacheoptions

Static $ cacheoptions = array (
'Cache' => true,
'Cache _ with_get_variables '=> true, // cache when a get variable exists
'Cache _ with_post_variables '=> false, // No cache is performed when a post variable exists.
'Cache _ with_cookie_variables '=> true, // cache when COOKIE variables exist
'Cache _ with_session_variables '=> true, // cache when session variables exist
'Make _ id_with_cookie_variables '=> false,
'Make _ id_with_session_variables '=> false,
'Make _ id_with_post_variables '=> false,
'Make _ id_with_files_variables '=> false,
'Make _ id_with_get_variables '=> true
);

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.