Customizing using S Caching method

Source: Internet
Author: User
<?php$info=s ("name", "Lizhaoyao"), $name =s ("name"), Var_dump ($name), function S ($key, $value = ", $cache _time=86400 {    $md =md5 ($key);//Encrypt name by MD45 hash    $dir = "./cache/";//define Cache Storage Path folder    if (!is_dir ($dir))    {        mkdir ($dir, ' 0777 ');//First detect if the folder exists    }    $file _name= $dir. $md;    if (empty ($value))    {        //to take the value out        if (file_exists ($file _name))        {            $cont =file_get_contents ($ file_name);            Return Unserialize ($cont);        } else{            echo "";        }    } else    {        //If the assignment is null, the cache is deleted if        ($value ===null)        {           return unlink ($file _name);        }        To be stored in        $data [' Value ']= $value;        $data [' Deadline ']=time () + $cache _time;        Return file_put_contents ($file _name,serialize ($data));}    ? >

Use this code to customize the read and use of a S method for caching

Customizing using S Caching method

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.