PHP Development App Interface (iv)

Source: Internet
Author: User

Core technology:
Caching technology, Scheduled tasks

1 static Cache,
2.Memcache Redis Cache
Use caching to reduce server pressure

Static caching of static files saved on disk
PHP operation cache: Generate cache, get cache, delete cache;

<?php

class File () {
private $_dir;
Const EXT = ". txt";
Public function __construct () {
$this->_dir=dirname (__file__). " /files/";
    }
/**
* Output communication data in an integrated manner
* @param string $key file name
* @param string $value data
* @param string $path path
* @return String
*/
Public function CacheData ($key, $value = ', $path = ') {
$filename = $this->_dir. $path. $key. Self::ext;

if ($value!== "") {
if (Is_null ($value)) {
return @unlink ($filename);
                }
//write value value to cache
$dir =dirname ($filename);
if (!is_dir ($dir)) {
mkdir ($dir, 0777);
                }

return file_put_contents ($filename, Json_encode ($value));

            }

if (!is_file ($filename)) {
return false;
}else{
return Json_decode (file_get_contents ($filename), true);
            }
    }
}
?>

============================================================================

<?php
/* Above function, $value is empty is to get the cache, not empty is to write,
Null is to delete cache */
$file = new file ();
if ($file->cachedata (' Index_mk_cache ', null)) {
echo "Success";
}else{
echo "Error";
}

?>

PHP Development App Interface (iv)

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.