| 1 |
lars |
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
|
|
2 |
<HTML>
|
|
|
3 |
<HEAD>
|
|
|
4 |
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-iso-8859-1">
|
|
|
5 |
<LINK REL="Start" HREF="index.html">
|
|
|
6 |
<LINK REL="Contents" HREF="toc.html">
|
|
|
7 |
<LINK REL="Prev" HREF="52Usingthecacheinyourscript.html">
|
|
|
8 |
<LINK REL="Next" HREF="54Somefinalcomments.html">
|
|
|
9 |
<STYLE TYPE="text/css"><!--
|
|
|
10 |
BODY { font-family: serif }
|
|
|
11 |
H1 { font-family: sans-serif }
|
|
|
12 |
H2 { font-family: sans-serif }
|
|
|
13 |
H3 { font-family: sans-serif }
|
|
|
14 |
H4 { font-family: sans-serif }
|
|
|
15 |
H5 { font-family: sans-serif }
|
|
|
16 |
H6 { font-family: sans-serif }
|
|
|
17 |
SUB { font-size: smaller }
|
|
|
18 |
SUP { font-size: smaller }
|
|
|
19 |
PRE { font-family: monospace }
|
|
|
20 |
A { text-decoration: none }
|
|
|
21 |
--></STYLE>
|
|
|
22 |
</HEAD>
|
|
|
23 |
<BODY>
|
|
|
24 |
<A HREF="toc.html">Contents</A>
|
|
|
25 |
<A HREF="52Usingthecacheinyourscript.html">Previous</A>
|
|
|
26 |
<A HREF="54Somefinalcomments.html">Next</A>
|
|
|
27 |
<HR NOSHADE>
|
|
|
28 |
<H2><A NAME="5_3">5.3 Using the cache with Client Side Image Maps</A></H2>
|
|
|
29 |
<P> You can also use the cache system for CSIM as well. The cache system
|
|
|
30 |
interface is slightly different in this case since the cache needs to
|
|
|
31 |
store<STRONG> both</STRONG> the cached image and the cached image-map.
|
|
|
32 |
It also needs to change due to the way CSIM HTML paradigm work. The two
|
|
|
33 |
major differences from the "standard" cache is</P>
|
|
|
34 |
<OL>
|
|
|
35 |
<LI> The cached version will<STRONG> not</STRONG> be stored in the
|
|
|
36 |
previous defined cache directory. See more below.</LI>
|
|
|
37 |
<LI> You must call an extra method, CheckCSIMCache(), to check the
|
|
|
38 |
cache, see more below.</LI>
|
|
|
39 |
</OL>
|
|
|
40 |
<P></P>
|
|
|
41 |
<P> The performance benefits even for simple CSIM images is around 50%
|
|
|
42 |
if the cache can be used and can of course be several 1000% if
|
|
|
43 |
construction of the image requires DB calls and other complex
|
|
|
44 |
operations which can be avoided.</P>
|
|
|
45 |
<P> Before reading further you should have an understanding on how the
|
|
|
46 |
CSIM works by reading the section "sing Client side image maps".</P>
|
|
|
47 |
<P> Please remember that when using CSIM you must end your script with a
|
|
|
48 |
call to <A href="">Graph::StrokeCSIM()</A> method instead of the <A href="">
|
|
|
49 |
Graph::Stroke()</A> used for non-csim.</P>
|
|
|
50 |
<P> To use the cache with CSIM you have to call the <A href="">
|
|
|
51 |
Graph::CheckCSIMCache()</A>. As with the caching for non-CSIM you have
|
|
|
52 |
to supply a name to be used for the cached version as well as an
|
|
|
53 |
optional timeout value. The default timeout value if nothing else is
|
|
|
54 |
specified is 60 minutes.</P>
|
|
|
55 |
<P> The name argument requires some more explanations. You must specify
|
|
|
56 |
a relative name here. For example "myimage" or perhaps
|
|
|
57 |
"firstpage/image3". Depending on your installation of JpGraph this will
|
|
|
58 |
now end up in the directory specified in the CSIMCACHE_DIR define. This
|
|
|
59 |
must also be a directory accessible by the normal web server. By
|
|
|
60 |
default a directory called "csimcache" will be created in the same
|
|
|
61 |
directory as the image script itself.</P>
|
|
|
62 |
<P> This has the drawback that the directory from where the script is
|
|
|
63 |
executed must be writable by the process running PHP. Best practice for
|
|
|
64 |
this is to keep the number of writable directory for PHP down to a
|
|
|
65 |
minimum and re-use the same directory as is used for the standard
|
|
|
66 |
cache. This however, require that your system administrator setup that
|
|
|
67 |
cache directory so that it also accessible by the HTTP server from the
|
|
|
68 |
htdocs root.</P>
|
|
|
69 |
<P> The CheckCSIMCache() method checks the cache for an existing cached
|
|
|
70 |
version and if found it returns it and halts execution of the script.
|
|
|
71 |
So, this call should be the first call after the creation of the
|
|
|
72 |
Graph() and before any heavy work is done to create the image so that
|
|
|
73 |
you can minimize the execution of the script in the case a match is
|
|
|
74 |
found.</P>
|
|
|
75 |
<P> So, the general structure of a script that uses CSIM and the cache
|
|
|
76 |
is<DIV class="phpscript"><CODE><FONT color="#000000"> <FONT color="#0000BB">
|
|
|
77 |
$graph </FONT><FONT color="#007700">= new </FONT><FONT color="#0000BB">
|
|
|
78 |
Graph</FONT><FONT color="#007700">(</FONT><FONT color="#0000BB">400</FONT><FONT
|
|
|
79 |
color="#007700">,</FONT><FONT color="#0000BB">300</FONT><FONT color="#007700">
|
|
|
80 |
);
|
|
|
81 |
<BR>
|
|
|
82 |
<BR></FONT><FONT color="#FF8000">// Check cache, 10 min timeout
|
|
|
83 |
<BR></FONT><FONT color="#0000BB">$graph</FONT><FONT color="#007700">-></FONT><FONT
|
|
|
84 |
color="#0000BB">CheckCSIMCache</FONT><FONT color="#007700">(</FONT><FONT color="#DD0000">
|
|
|
85 |
"image1"</FONT><FONT color="#007700">,</FONT><FONT color="#0000BB">10</FONT><FONT
|
|
|
86 |
color="#007700">);
|
|
|
87 |
<BR>
|
|
|
88 |
<BR></FONT><FONT color="#FF8000">
|
|
|
89 |
// !! If cached version exists, execution halts here !!
|
|
|
90 |
<BR>
|
|
|
91 |
<BR>//
|
|
|
92 |
<BR>// ... Construct the image with heavy DB calls etc, etc
|
|
|
93 |
<BR>//
|
|
|
94 |
<BR>
|
|
|
95 |
<BR></FONT><FONT color="#0000BB">$graph</FONT><FONT color="#007700">-></FONT><FONT
|
|
|
96 |
color="#0000BB">StrokeCSIM</FONT><FONT color="#007700">();</FONT><FONT color="#0000BB">
|
|
|
97 |
</FONT></FONT></CODE></DIV></P>
|
|
|
98 |
<P> Please note that you<STRONG> do not</STRONG> need to pass any
|
|
|
99 |
argument to the final call to StrokeCSIM() as you do when not using the
|
|
|
100 |
cache.<DIV class="note"><B>Note:</B> The CSIM caching works by storing
|
|
|
101 |
two files in the cache directory. One file being the image and the
|
|
|
102 |
other file being the corresponding image map as a pure HTML file.</DIV></P>
|
|
|
103 |
<HR NOSHADE>
|
|
|
104 |
<A HREF="toc.html">Contents</A>
|
|
|
105 |
<A HREF="52Usingthecacheinyourscript.html">Previous</A>
|
|
|
106 |
<A HREF="54Somefinalcomments.html">Next</A>
|
|
|
107 |
</BODY>
|
|
|
108 |
</HTML>
|