63 lines
6.6 KiB
HTML
63 lines
6.6 KiB
HTML
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Chapter 9. Using the JpGraph cache system</title><link rel="stylesheet" type="text/css" href="manual.css"><meta name="generator" content="DocBook XSL Stylesheets V1.76.0"><link rel="home" href="index.html" title="JpGraph Manual"><link rel="up" href="pt02.html" title="Part II. Basic graph creation"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 9. Using the JpGraph cache system</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center">Part II. Basic graph creation</th><td width="20%" align="right"> </td></tr></table><hr></div><div class="chapter" title="Chapter 9. Using the JpGraph cache system"><div class="titlepage"><div><div><h2 class="title"><a name="chap.using-cache"></a>Chapter 9. Using the JpGraph cache system</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="ch09.html#id2500903">9.1. Enabling the library cache system</a></span></dt><dt><span class="sect1"><a href="ch09s02.html">9.2. Permission settings for the cache files</a></span></dt><dt><span class="sect1"><a href="ch09s03.html">9.3. Using the cache in your script</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch09s03.html#id2535216">9.3.1. Manually controlling the cached image</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch09s04.html">9.4. Using the cache with Client Side Image Maps (CSIM)</a></span></dt></dl></div>
|
||
|
||
<p>To reduce load on the web server JpGraph implements an advanced caching system which
|
||
avoids the burden of always having to run the full image script. The library supports
|
||
two primary ways of significantly increase performance, using the built in cache system
|
||
described in this section and the use of a PHP accelerator described in <a class="xref" href="ch11.html" title="Chapter 11. NuSphere PHP accelerator">Chapter 11. <i>NuSphere PHP accelerator</i></a></p>
|
||
<p>Depending on the complexity of the image script, for example if it is doing several DB
|
||
lookups, the use of the library cache system (which will avoid running the graph scripts
|
||
completely if possible) can make a for very drastic performance increase.</p>
|
||
<p><a class="xref" href="ch09.html#fig.cache-overview" title="Figure 9.1. Library cache principle">Figure 9.1. Library cache principle</a>shows an overview of the cache system in the library.</p>
|
||
<p>
|
||
</p><div class="figure"><a name="fig.cache-overview"></a><p class="title"><b>Figure 9.1. Library cache principle</b></p><div class="figure-contents">
|
||
|
||
<div class="mediaobject"><img src="images/cache_principles.png" alt="Library cache principle"></div>
|
||
</div></div><p><br class="figure-break">
|
||
</p>
|
||
<p>The rationale behind this is the observation that very few graphs are really
|
||
real-time, i.e. needs to be updated absolutely every time the graphing script is called.
|
||
For many graphs in a WEB-environment one can often get good precision by restricting the
|
||
graphs to only be updated, say, a few times each day. Of course, if truly live data is
|
||
what is needed then the cache system can not be used since then, by the nature of live
|
||
data, the graph script must be called at each instance to get the latest available data,
|
||
most probably from a database.</p>
|
||
<div class="sect1" title="Enabling the library cache system"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2500903"></a>Enabling the library cache system</h2></div></div></div>
|
||
|
||
<p>The enabling and disabling of the cache system is controlled by three defines in
|
||
<code class="filename">jpg-config.php</code></p>
|
||
<p>
|
||
</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
|
||
<p><code class="code">DEFINE("USE_CACHE",true)</code></p>
|
||
</li><li class="listitem">
|
||
<p><code class="code">DEFINE("READ_CACHE",true)</code></p>
|
||
</li><li class="listitem">
|
||
<p><code class="code">DEFINE("CACHE_DIR","/tmp/jpgraph_cache/")</code></p>
|
||
</li></ol></div><p>
|
||
</p>
|
||
<p>The first of these, <code class="code">USE_CACHE</code>, is the master-switch which must be set
|
||
to true to enable the caching system. </p>
|
||
<p>The second switch, <code class="code">READ_CACHE</code> very seldom needs to be changed. This
|
||
second switch basically tells whether or not JpGraph should ever look in the cache.
|
||
Setting this to false and the master-switch to true would then always generate a new
|
||
updated image file in the cache and this new image would be send back to the
|
||
browser. The main use for this (admittedly) strange setting is if you like to have
|
||
the side effect of the script that a fresh image is always stored in the cache
|
||
directory. </p>
|
||
<p>The third define is not really a switch but a directory specification that tells
|
||
the library what directory to use as the cache directory (where the cached images
|
||
are stored). </p>
|
||
<p>The cache directory (<code class="code">CACHE_DIR</code>) can be set to an arbitrary directory
|
||
but the important thing to keep in mind is that the cache directory must be read and
|
||
writable for the process running PHP. </p>
|
||
<p>
|
||
</p><div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
|
||
<p>The directory name given should be an absolute directory path and <span class="bold"><strong>not</strong></span> a file path relative to the document
|
||
root.</p>
|
||
</div><p>
|
||
</p>
|
||
</div>
|
||
|
||
|
||
|
||
</div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"> </td><td width="20%" align="center"><a accesskey="u" href="pt02.html">Up</a></td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>
|