(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 ";}