var_export 文件缓存经常使用 输出或返回一个变量的字符串表示
[php] view plain copy
- /**
- * 写入缓存
- *
- * @param string $id
- * @param mixed $data
- * @param array $policy
- */
- public function set($mode, $id, $data, $expired = -1)
- {
- if( empty($mode) || empty($id) ){return false;}
- $path = $this->getComFilename($mode ,$id);
- $expired = ($expired < 0) ? -1 : time() + $expired;
- $content = array(
- ‘expired‘ => $expired,
- ‘data‘ => $data,
- );
- $content = ‘<?php return ‘ . var_export($content, true) . ‘;‘;
- // 写入缓存,并去掉多余空格
- file_put_contents($path, $content, LOCK_EX);
- // file_put_contents($path, php_strip_whitespace($path), LOCK_EX);
- clearstatcache();
- $this->_cachelist($path,$mode);//写缓存列表文件
- return true;
- }
时间: 2024-10-31 07:26:21