3 pCache - Faster renderding using data cache
4 Copyright (C) 2008 Jean-Damien POGOLOTTI
5 Version 1.1.2 last updated on 06/17/08
7 http://pchart.sourceforge.net
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 1,2,3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 Class initialisation :
23 pCache($CacheFolder="Cache/")
26 GetFromCache($ID,$Data)
27 WriteToCache($ID,$Data,$Picture)
28 DeleteFromCache($ID,$Data)
34 /* pCache class definition */
38 var $CacheFolder = "Cache/";
40 /* Create the pCache object */
41 function pCache($CacheFolder="Cache/")
43 $this->CacheFolder = $CacheFolder;
46 /* This function is clearing the cache folder */
49 if ($handle = opendir($this->CacheFolder))
51 while (false !== ($file = readdir($handle)))
53 if ( $file != "." && $file != ".." )
54 unlink($this->CacheFolder.$file);
60 /* This function is checking if we have an offline version of this chart */
61 function IsInCache($ID,$Data,$Hash="")
64 $Hash = $this->GetHash($ID,$Data);
66 if ( file_exists($this->CacheFolder.$Hash) )
72 /* This function is making a copy of drawn chart in the cache folder */
73 function WriteToCache($ID,$Data,$Picture)
75 $Hash = $this->GetHash($ID,$Data);
76 $FileName = $this->CacheFolder.$Hash;
78 imagepng($Picture->Picture,$FileName);
81 /* This function is removing any cached copy of this chart */
82 function DeleteFromCache($ID,$Data)
84 $Hash = $this->GetHash($ID,$Data);
85 $FileName = $this->CacheFolder.$Hash;
87 if ( file_exists($FileName ) )
91 /* This function is retrieving the cached picture if applicable */
92 function GetFromCache($ID,$Data)
94 $Hash = $this->GetHash($ID,$Data);
95 if ( $this->IsInCache("","",$Hash ) )
97 $FileName = $this->CacheFolder.$Hash;
99 header('Content-type: image/png');
100 @readfile($FileName);
105 /* This function is building the graph unique hash key */
106 function GetHash($ID,$Data)
109 foreach($Data as $key => $Values)
112 foreach($Values as $Serie => $Value)
113 $tKey = $tKey.$Serie.$Value;
114 $mKey = $mKey.md5($tKey);