2
/////////////////////////////////////////////////////////
4
// include/cache.FS.inc
6
// (C)Copyright 2003 Ryo Chijiiwa <Ryo@IlohaMail.org>
8
// This file is part of IlohaMail, and released under GPL.
9
// See COPYING, or http://www.fsf.org/copyleft/gpl.html
11
/////////////////////////////////////////////////////////
12
/********************************************************
13
PURPOSE: Unified interface to read/write cache
15
********************************************************/
17
function cache_read($user, $host, $key){
20
//check if file is there
21
$user_dir = ereg_replace("[\\/]", "", $user.".".$host);
22
$path = $CACHE_DIR.$user_dir."/".$key;
23
if (!@file_exists(realpath($path))) return false;
26
$fp = fopen($path, "r");
27
if (!$fp) return false;
31
$data = fread($fp, filesize($path));
32
if ($data) $data = unserialize($data);
39
function cache_write($user, $host, $key, $data){
42
//open file for writing
43
$user_dir = ereg_replace("[\\/]", "", $user.".".$host);
44
$path = $CACHE_DIR.$user_dir."/".$key;
45
$fp = @fopen($path, "w");
46
if (!$fp) return false;
49
fputs($fp, serialize($data));
56
function cache_clear($user, $host, $key){
59
//check if file is there
60
$user_dir = ereg_replace("[\\/]", "", $user.".".$host);
61
$path = $CACHE_DIR.$user_dir."/".$key;
62
if (!@file_exists(realpath($path))) return false;
63
else return unlink($path);
66
function cache_clear_all($user, $host){
70
$cacheDir = $CACHE_DIR.ereg_replace("[\\/]", "", $user.".".$host);
71
if (@is_dir(realpath($cacheDir))){
72
if ($handle = opendir($cacheDir)) {
73
while (false !== ($file = readdir($handle))) {
74
if ($file != "." && $file != "..") {
75
$file_path = $cacheDir."/".$file;