<?php
class
cache
{
var
$cachefile
;
var
$cachefilevar
;
function
cache()
{
$s
=
array
(
"."
,
"/"
);
$r
=
array
(
"_"
,
""
);
$this
->cachefilevar=
str_replace
(
$s
,
$r
,
$_SERVER
[
"SCRIPT_NAME"
]).
"_"
.
$_GET
[_ActionVar_];
$this
->cachefile=
$this
->cachefilevar.
"."
.md5(
$_SERVER
[
"REQUEST_URI"
]);
}
function
delete
()
{
$d
= dir(_CachePath_);
$strlen
=
strlen
(
$this
->cachefilevar);
while
(false !== (
$entry
=
$d
->read()))
{
if
(
substr
(
$entry
,0,
$strlen
)==
$this
->cachefilevar)
{
if
(!unlink(_CachePath_.
"/"
.
$entry
)) {
echo
"Cache目录无法写入"
;
exit
;}
}
}
}
function
check()
{
if
(_ReCacheTime_+0>0)
{
$var
=@file(_CachePath_.
"/"
.
$this
->cachefilevar);
$var
=
$var
[0];
if
(time()-
$var
>_ReCacheTime_)
{
$this
->
delete
();
$ischage
=true;
}
}
$file
=_CachePath_.
"/"
.
$this
->cachefile;
return
(
file_exists
(
$file
)
and
_CacheEnable_
and
!
$ischange
);
}
function
read()
{
$file
=_CachePath_.
"/"
.
$this
->cachefile;
if
(_CacheEnable_)
return
readfile(
$file
);
else
return
false;
}
function
write(
$output
)
{
$file
=_CachePath_.
"/"
.
$this
->cachefile;
if
(_CacheEnable_)
{
$fp
=@
fopen
(
$file
,
'w'
);
if
(!@
fputs
(
$fp
,
$output
)) {
echo
"模板Cache写入失败"
;
exit
;}
@fclose(
$fp
);
if
(_ReCacheTime_+0>0)
{
$file
=_CachePath_.
"/"
.
$this
->cachefilevar;
$fp
=@
fopen
(
$file
,
'w'
);
if
(!@fwrite(
$fp
,time())) {
echo
"Cache目录无法写入"
;
exit
;}
@fclose(
$fp
);
}
}
}
}
?>