admin | 43a823e | 2006-09-27 01:57:10 +0000 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
| 2 | <html>
|
| 3 | <head>
|
| 4 |
|
| 5 | <title>Code Igniter User Guide</title>
|
| 6 |
|
| 7 | <style type='text/css' media='all'>@import url('../userguide.css');</style>
|
| 8 | <link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
|
| 9 |
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 10 | <script type="text/javascript" src="../nav/nav.js"></script>
|
admin | 2296fc3 | 2006-09-27 21:07:02 +0000 | [diff] [blame] | 11 | <script type="text/javascript" src="../nav/prototype.lite.js"></script>
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 12 | <script type="text/javascript" src="../nav/moo.fx.js"></script>
|
admin | 43a823e | 2006-09-27 01:57:10 +0000 | [diff] [blame] | 13 | <script type="text/javascript">
|
| 14 | window.onload = function() {
|
| 15 | myHeight = new fx.Height('nav', {duration: 400});
|
| 16 | myHeight.hide();
|
| 17 | }
|
| 18 | </script>
|
| 19 |
|
| 20 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
| 21 | <meta http-equiv='expires' content='-1' />
|
| 22 | <meta http-equiv= 'pragma' content='no-cache' />
|
| 23 | <meta name='robots' content='all' />
|
| 24 | <meta name='author' content='Rick Ellis' />
|
| 25 | <meta name='description' content='Code Igniter User Guide' />
|
| 26 |
|
| 27 | </head>
|
| 28 | <body>
|
| 29 |
|
| 30 | <!-- START NAVIGATION -->
|
| 31 | <div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
|
| 32 | <div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle.jpg" width="153" height="44" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
|
| 33 | <div id="masthead">
|
| 34 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 35 | <tr>
|
| 36 | <td><h1>Code Igniter User Guide Version 1.5.0</h1></td>
|
| 37 | <td id="breadcrumb_right"><a href="../toc.html">Full Table of Contents</a></td>
|
| 38 | </tr>
|
| 39 | </table>
|
| 40 | </div>
|
| 41 | <!-- END NAVIGATION -->
|
| 42 |
|
| 43 |
|
| 44 | <!-- START BREADCRUMB -->
|
| 45 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 46 | <tr>
|
| 47 | <td id="breadcrumb">
|
| 48 | <a href="http://www.codeigniter.com/">Code Igniter Home</a> ›
|
| 49 | <a href="../index.html">User Guide Home</a> ›
|
| 50 | <a href="index.html">Database Library</a> ›
|
| 51 | Database Caching Class
|
| 52 | </td>
|
| 53 | <td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="www.codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
|
| 54 | </tr>
|
| 55 | </table>
|
| 56 | <!-- END BREADCRUMB -->
|
| 57 |
|
| 58 |
|
| 59 | <br clear="all" />
|
| 60 |
|
| 61 |
|
| 62 | <!-- START CONTENT -->
|
| 63 | <div id="content">
|
| 64 |
|
| 65 | <h1>Database Caching Class</h1>
|
| 66 |
|
admin | 5294f4f | 2006-10-06 02:10:05 +0000 | [diff] [blame^] | 67 | <p>The Database Caching Class permits you to cache your queries as text files for reduced database load.</p>
|
admin | 43a823e | 2006-09-27 01:57:10 +0000 | [diff] [blame] | 68 |
|
admin | 5ffba1e | 2006-10-05 04:23:18 +0000 | [diff] [blame] | 69 | <p class="important"><strong>Important:</strong> This class is initialized automatically by the database driver
|
admin | 5294f4f | 2006-10-06 02:10:05 +0000 | [diff] [blame^] | 70 | when caching is enabled. Do NOT load this class manually.<br /><br />
|
admin | 43a823e | 2006-09-27 01:57:10 +0000 | [diff] [blame] | 71 |
|
admin | 5294f4f | 2006-10-06 02:10:05 +0000 | [diff] [blame^] | 72 | <strong>Also note:</strong> Not all query result functions are available when you use caching. Please read this page carefully.</p>
|
admin | 43a823e | 2006-09-27 01:57:10 +0000 | [diff] [blame] | 73 |
|
admin | 11c06c7 | 2006-10-05 05:12:27 +0000 | [diff] [blame] | 74 | <h2>Enabling Caching</h2>
|
| 75 |
|
admin | 5294f4f | 2006-10-06 02:10:05 +0000 | [diff] [blame^] | 76 | <p>Caching is enabled in three steps:</p>
|
admin | 11c06c7 | 2006-10-05 05:12:27 +0000 | [diff] [blame] | 77 |
|
| 78 | <ul>
|
admin | 5294f4f | 2006-10-06 02:10:05 +0000 | [diff] [blame^] | 79 | <li>Create a writable directory on your server where the cache files can be stored.</li>
|
| 80 | <li>Set the path to your cache folder in your <dfn>application/config/database.php</dfn> file.</li>
|
| 81 | <li>Enable the caching feature, either globally by setting the preference in your <dfn>application/config/database.php</dfn> file, or manually as described below.</li>
|
admin | 11c06c7 | 2006-10-05 05:12:27 +0000 | [diff] [blame] | 82 | </ul>
|
admin | 43a823e | 2006-09-27 01:57:10 +0000 | [diff] [blame] | 83 |
|
| 84 |
|
admin | 5294f4f | 2006-10-06 02:10:05 +0000 | [diff] [blame^] | 85 | <h2>How Does Caching Work?</h2>
|
admin | f3428b5 | 2006-10-05 05:19:15 +0000 | [diff] [blame] | 86 |
|
admin | 5294f4f | 2006-10-06 02:10:05 +0000 | [diff] [blame^] | 87 | <p>Code Igniter's query caching system happens dynamically when your pages are viewed.
|
| 88 | When caching is enabled, the first time a webpage is loaded, the query result object will
|
| 89 | be serialized and stored in a text file on your server. The next time the page is loaded the cache file will be used instead of
|
| 90 | accessing your database. Your database usage can effectively be reduced to zero for any pages that have been cached.</p>
|
admin | f3428b5 | 2006-10-05 05:19:15 +0000 | [diff] [blame] | 91 |
|
admin | 5294f4f | 2006-10-06 02:10:05 +0000 | [diff] [blame^] | 92 | <p>Only <dfn>read-type</dfn> (SELECT) queries can be cached, since these are the only type of queries that produce a result.
|
| 93 | <dfn>Write-type</dfn> (INSERT, UPDATE, etc.) queries, since they don't generate a result, will not be cached by the system.</p>
|
admin | f3428b5 | 2006-10-05 05:19:15 +0000 | [diff] [blame] | 94 |
|
admin | 5294f4f | 2006-10-06 02:10:05 +0000 | [diff] [blame^] | 95 | <p>Cache files do NOT expire. Any queries that have been cached will remain cached until you delete them. The caching system does
|
| 96 | have an "auto-delete"feature, as described below. It also lets you manually clear caches associated with individulal pages, or
|
| 97 | you can delete the entire collection of cache files.</p>
|
admin | f3428b5 | 2006-10-05 05:19:15 +0000 | [diff] [blame] | 98 |
|
admin | 5294f4f | 2006-10-06 02:10:05 +0000 | [diff] [blame^] | 99 | <h2>Will Caching Improve Your Site's Performance?</h2>
|
| 100 |
|
| 101 | <p>Maybe. Whether you see a performance gain as a result of caching depends on many factors.
|
| 102 | For example, if you have a highly optimized database under very little load, you probably won't see a performance boost.
|
| 103 | If your database is under heavy use you probably will see an improved response, assuming your filesystem is not
|
| 104 | overly taxed. Remember that caching simply changes how your information is retrieved, shifting it from being a database
|
| 105 | operation to a filesystem one.</p>
|
| 106 |
|
| 107 | <p>In some clustered server environments caching may be detrimental since filesystem operations are so intense.
|
| 108 | On single servers (particularly in shared enironments) caching will probably be beneficial. Unfortunately there is no
|
| 109 | single answer to the question of whether you should cache your database. It really depends on your situation.</p>
|
| 110 |
|
| 111 | <h2>How are Cache Files Stored?</h2>
|
| 112 |
|
| 113 | <p>Code Igniter places the result of EACH query into its own cache file. Sets of cache files are further organized into
|
| 114 | sub-folders corrsponding to your controller functions.</p>
|
| 115 |
|
| 116 | <p>For example, let's say you have a controller called <dfn>blog</dfn> with a function called <dfn>comments</dfn> that
|
| 117 | contains three queries. The caching system will create a cache folder
|
| 118 | called <kbd>blog_comments</kbd>, into which it will write three cache files.</p>
|
| 119 |
|
| 120 | <p>If your have dynamic queries that change based on inormation in your URI (when using pagination, for example), each instance of
|
| 121 | the query will produce its own cache file. It's possible, therefore, to end up with many times more cache files than you have
|
| 122 | queries.</p>
|
admin | f3428b5 | 2006-10-05 05:19:15 +0000 | [diff] [blame] | 123 |
|
| 124 |
|
admin | 5294f4f | 2006-10-06 02:10:05 +0000 | [diff] [blame^] | 125 | <h2>Managing your Cache Files</h2>
|
| 126 |
|
| 127 | <p>Since cache files do not expire, you'll need to build deletion routines into your application. For example, let's say you have a blog
|
| 128 | that allows user commenting. Whenever a new comment is submitted you'll want to delete the cache files associated with the
|
| 129 | controller function that serves up your comments. You'll find two delete functions described below that help you
|
| 130 | clear data.</p>
|
admin | f3428b5 | 2006-10-05 05:19:15 +0000 | [diff] [blame] | 131 |
|
| 132 |
|
admin | 5294f4f | 2006-10-06 02:10:05 +0000 | [diff] [blame^] | 133 | <h1>Function Reference</h1>
|
admin | f3428b5 | 2006-10-05 05:19:15 +0000 | [diff] [blame] | 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
admin | 43a823e | 2006-09-27 01:57:10 +0000 | [diff] [blame] | 147 |
|
| 148 |
|
| 149 | </div>
|
| 150 | <!-- END CONTENT -->
|
| 151 |
|
| 152 |
|
| 153 | <div id="footer">
|
| 154 | <p>
|
| 155 | Previous Topic: <a href="call_function.html">Custom Function Calls</a>
|
| 156 | ·
|
| 157 | <a href="#top">Top of Page</a> ·
|
| 158 | <a href="../index.html">User Guide Home</a> ·
|
| 159 | Next Topic: <a href="export.html">Database Export Class</a>
|
| 160 | <p>
|
| 161 | <p><a href="http://www.codeigniter.com">Code Igniter</a> · Copyright © 2006 · <a href="http://www.pmachine.com">pMachine, Inc.</a></p>
|
| 162 | </div>
|
| 163 |
|
| 164 | </body>
|
| 165 | </html> |