Blame | Letzte Änderung | Log anzeigen | RSS feed
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-iso-8859-1"><LINK REL="Start" HREF="index.html"><LINK REL="Contents" HREF="toc.html"><LINK REL="Prev" HREF="62Usingthecacheinyourscript.html"><LINK REL="Next" HREF="64Somefinalcomments.html"><STYLE TYPE="text/css"><!--BODY { font-family: serif }H1 { font-family: sans-serif }H2 { font-family: sans-serif }H3 { font-family: sans-serif }H4 { font-family: sans-serif }H5 { font-family: sans-serif }H6 { font-family: sans-serif }SUB { font-size: smaller }SUP { font-size: smaller }PRE { font-family: monospace }A { text-decoration: none }--></STYLE></HEAD><BODY><A HREF="toc.html">Contents</A><A HREF="62Usingthecacheinyourscript.html">Previous</A><A HREF="64Somefinalcomments.html">Next</A><HR NOSHADE><H2><A NAME="6_3">6.3 Using the cache with Client Side Image Maps</A></H2><P> You can also use the cache system for CSIM as well. The cache systeminterface is slightly different in this case since the cache needs tostore<STRONG> both</STRONG> the cached image and the cached image-map.It also needs to change due to the way CSIM HTML paradigm work. The twomajor differences from the "standard" cache is</P><OL><LI> The cached version will<STRONG> not</STRONG> be stored in theprevious defined cache directory. See more below.</LI><LI> You must call an extra method, CheckCSIMCache(), to check thecache, see more below.</LI></OL><P></P><P> The performance benefits even for simple CSIM images is around 50%if the cache can be used and can of course be several 1000% ifconstruction of the image requires DB calls and other complexoperations which can be avoided.</P><P> Before reading further you should have an understanding on how theCSIM works by reading the section "sing Client side image maps".</P><P> Please remember that when using CSIM you must end your script with acall to <A href="">Graph::StrokeCSIM()</A> method instead of the <A href="">Graph::Stroke()</A> used for non-csim.</P><P> To use the cache with CSIM you have to call the <A href="">Graph::CheckCSIMCache()</A>. As with the caching for non-CSIM you haveto supply a name to be used for the cached version as well as anoptional timeout value. The default timeout value if nothing else isspecified is 60 minutes.</P><P> The name argument requires some more explanations. You must specifya relative name here. For example "myimage" or perhaps"firstpage/image3". Depending on your installation of JpGraph this willnow end up in the directory specified in the CSIMCACHE_DIR define. Thismust also be a directory accessible by the normal web server. Bydefault a directory called "csimcache" will be created in the samedirectory as the image script itself.</P><P> This has the drawback that the directory from where the script isexecuted must be writable by the process running PHP. Best practice forthis is to keep the number of writable directory for PHP down to aminimum and re-use the same directory as is used for the standardcache. This however, require that your system administrator setup thatcache directory so that it also accessible by the HTTP server from thehtdocs root.</P><P> The CheckCSIMCache() method checks the cache for an existing cachedversion and if found it returns it and halts execution of the script.So, this call should be the first call after the creation of theGraph() and before any heavy work is done to create the image so thatyou can minimize the execution of the script in the case a match isfound.</P><P> So, the general structure of a script that uses CSIM and the cacheis<DIV class="phpscript"><CODE><FONT color="#000000"> <FONT color="#0000BB"> $graph </FONT><FONT color="#007700">= new </FONT><FONT color="#0000BB">Graph</FONT><FONT color="#007700">(</FONT><FONT color="#0000BB">400</FONT><FONTcolor="#007700">,</FONT><FONT color="#0000BB">300</FONT><FONT color="#007700">);<BR><BR></FONT><FONT color="#FF8000">// Check cache, 10 min timeout<BR></FONT><FONT color="#0000BB">$graph</FONT><FONT color="#007700">-></FONT><FONTcolor="#0000BB">CheckCSIMCache</FONT><FONT color="#007700">(</FONT><FONT color="#DD0000">"image1"</FONT><FONT color="#007700">,</FONT><FONT color="#0000BB">10</FONT><FONTcolor="#007700">);<BR><BR></FONT><FONT color="#FF8000">// !! If cached version exists, execution halts here !!<BR><BR>//<BR>// ... Construct the image with heavy DB calls etc, etc<BR>//<BR><BR></FONT><FONT color="#0000BB">$graph</FONT><FONT color="#007700">-></FONT><FONTcolor="#0000BB">StrokeCSIM</FONT><FONT color="#007700">();</FONT><FONT color="#0000BB"></FONT></FONT></CODE></DIV></P><P> Please note that you<STRONG> do not</STRONG> need to pass anyargument to the final call to StrokeCSIM() as you do when not using thecache.<DIV class="note"><B>Note:</B> The CSIM caching works by storingtwo files in the cache directory. One file being the image and theother file being the corresponding image map as a pure HTML file.</DIV></P><HR NOSHADE><A HREF="toc.html">Contents</A><A HREF="62Usingthecacheinyourscript.html">Previous</A><A HREF="64Somefinalcomments.html">Next</A></BODY></HTML>