求一个php数据缓存类,谢谢! 求一个php数据缓存类,谢谢!有例子更好啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <?phpclass Data_cache{ //缓存文件存放的地址 private $file = "/usr/www/program/cache/"; //文件的名称 private $filename = "filename"; //需要写入缓存文件的数据 private $data = ""; public function __construct($filename,$data) { $this->filename = $filename; $this->data = $data; if($this->judge_cache_file_exists()) { $this->put_data_to_file(); } } //写入缓存文件 public function put_data_to_file($data) { if(isset($data)) { $dir = $file.md5($filename).".php"; file_put_contents($dir,$this->data); }else{ return FALSE; } } //判断缓存文件是否存在 public function judge_cache_file_exists() { return file_get_contents($file.md5($filename).".php",$this->data); }}?> $data = "这是需要缓存的数据";$filename = "filename";$cache = new Data_cache($filename,$data); 刚看到php有个两颗星的说:这年头用dw写程序是历史的倒退。 谁能帮忙解决IIS支持PHP的配置问题 mysql + adodb 在unix下能用吗 为什么服务器上的PHP 解析不了 <?=$a?> 要怎么设置才可以呢? php 职何导入导出XLS 文件 还是session问题,真是搞不定了 请资深人士开讲座——数据库 php在一般项目中的常用到的函数,100分提供 有问题吗? 请问如何得到Zend Encode,及怎样安装? PHP 从函数中返回值和对函数的引用两者的定义有什么区别吗 Wordpress编辑器与发布到前台格式的问题
<?php
class Data_cache
{
//缓存文件存放的地址
private $file = "/usr/www/program/cache/";
//文件的名称
private $filename = "filename";
//需要写入缓存文件的数据
private $data = "";
public function __construct($filename,$data)
{
$this->filename = $filename;
$this->data = $data;
if($this->judge_cache_file_exists())
{
$this->put_data_to_file();
}
}
//写入缓存文件
public function put_data_to_file($data)
{
if(isset($data))
{
$dir = $file.md5($filename).".php";
file_put_contents($dir,$this->data);
}else{
return FALSE;
}
}
//判断缓存文件是否存在
public function judge_cache_file_exists()
{
return file_get_contents($file.md5($filename).".php",$this->data);
}
}?>
$data = "这是需要缓存的数据";
$filename = "filename";
$cache = new Data_cache($filename,$data);