Static cache for php app Interfaces

Source: Internet
Author: User
(1) Static cache the essence of the technology here is that we temporarily store some of the data we need in some files on the server .? PhpclassFile {private $ _ dir; constEXTphp; publicfunction _ construct () {$ this-_ dirname (_ FILE _). files;} publicfunctioncache

(1) Static cache the essence of the technology here is that we temporarily store some of the data we need in some files on the server. ? Php class File {private $ _ dir; const EXT = 'php'; public function _ construct () {$ this-_ dir = dirname (_ FILE __). '/files/';} public function cache

(1)StaticCache
The essence of the technology here is that we temporarily store some of the data we need in some files on the server.


  _ Dir = dirname (_ FILE __). '/files/';} public function cacheDate ($ key, $ value = '', $ path ='') {$ filename = $ this-> _ dir. $ path. $ key. self: EXT; // write the valueCacheIf ($ value! = '') {// If the value is null if (is_null ($ value) {return unlink ($ filename);} $ 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 );}}}

A class is encapsulated here, and the following is the test code.


  1, 'name' => 'singwa ', 'type' => array (123, 6), 'test' => array (, 67 => array, 'tsysa '),); $ file = new File (); // AddCacheIf ($ file-> cacheDate ('index _ mk_cache '), $ data) {var_dump ($ file-> cacheDate ('index _ mk_cache '); echo "success" ;}else {echo "error" ;}// retrieveCacheIf ($ file-> cacheDate ('index _ mk_cache ') {var_dump ($ file-> cacheDate ('index _ mk_cache'); echo "success ";} else {echo "error";} // DeleteCacheIf ($ file-> cacheDate ('index _ mk_cache '), $ value = null) {var_dump ($ file-> cacheDate ('index _ mk_cache ')); echo "success";} else {echo "error ";}

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.