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 |
|
| 67 | <p>The Database Caching Class contains functions that permit you to cache your queries.</p>
|
| 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 | 11c06c7 | 2006-10-05 05:12:27 +0000 | [diff] [blame^] | 70 | when caching is enabled. Do NOT load this class manually.
|
admin | 43a823e | 2006-09-27 01:57:10 +0000 | [diff] [blame] | 71 | More info below...</p>
|
| 72 |
|
admin | 5ffba1e | 2006-10-05 04:23:18 +0000 | [diff] [blame] | 73 | <h2>How Does Caching Work?</h2>
|
admin | 43a823e | 2006-09-27 01:57:10 +0000 | [diff] [blame] | 74 |
|
admin | 11c06c7 | 2006-10-05 05:12:27 +0000 | [diff] [blame^] | 75 | <p>When caching is enabled, anytime a "read" type query (SELECT) is run, the result object will
|
| 76 | be serialized and stored in a text file on your server. Subsequent calls to that query will use the result from the cache file
|
| 77 | rather then accessing your database. In other words, the first time a page is loaded a cache file will be written.
|
| 78 | The next time the page is loaded the cached file will be used.</p>
|
admin | 43a823e | 2006-09-27 01:57:10 +0000 | [diff] [blame] | 79 |
|
admin | 11c06c7 | 2006-10-05 05:12:27 +0000 | [diff] [blame^] | 80 | <p>When a "write" type query (INSERT, UPDATE, etc.) is run , any cache files associated with the particular page being viewed
|
| 81 | will be deleted automatically. In some cases you may need to update some data with every page load (user stats, for example).
|
| 82 | In these cases you'll proabably want to manually disable caching just before running your "write" query, then re-enable it just
|
| 83 | after. Otherwise, your site will be caught ina cycle of writing/deleting caches, creating more load then if you were not using
|
| 84 | caching. More information on this will be found below.</p>
|
admin | 43a823e | 2006-09-27 01:57:10 +0000 | [diff] [blame] | 85 |
|
admin | 43a823e | 2006-09-27 01:57:10 +0000 | [diff] [blame] | 86 |
|
admin | 11c06c7 | 2006-10-05 05:12:27 +0000 | [diff] [blame^] | 87 | <p>Although caching will reduce your database load, dealing with cache files does generate more
|
| 88 | up-front processing and file-system operations, as cache files are created and read. Instead of accessing your database for information
|
| 89 | text files are used.</p>
|
admin | 43a823e | 2006-09-27 01:57:10 +0000 | [diff] [blame] | 90 |
|
admin | 11c06c7 | 2006-10-05 05:12:27 +0000 | [diff] [blame^] | 91 | <p>Whether you see a performance gain as a result of caching is dependant on many factors.
|
admin | 5ffba1e | 2006-10-05 04:23:18 +0000 | [diff] [blame] | 92 | For example, if you have a highly optimized database under very little load, you probably won't see a performance boost.
|
| 93 | If your database is under heavy use you probably will see an improved response, assuming your filesystem is not
|
admin | 11c06c7 | 2006-10-05 05:12:27 +0000 | [diff] [blame^] | 94 | overly taxed. In some clustered server environments caching may be detrimental since filesystem operations are so intense.
|
| 95 | On single servers (particularly in shared enironments) caching will probably be beneficial. Unfortunately there is no
|
| 96 | single answer to the question of whether you should cache your database. It really depends on your situation.</p>
|
admin | 43a823e | 2006-09-27 01:57:10 +0000 | [diff] [blame] | 97 |
|
admin | 11c06c7 | 2006-10-05 05:12:27 +0000 | [diff] [blame^] | 98 | <h2>Enabling Caching</h2>
|
| 99 |
|
| 100 | <p>Enabling caching requires three steps:</p>
|
| 101 |
|
| 102 | <ul>
|
| 103 | <li>Creating a directory on your server where the cache files will be written.</li>
|
| 104 | <li>Setting the path to your cache folder in your <dfn>application/config/database.php</dfn> file.</li>
|
| 105 | <li>Enalbling the caching preference either in your database config file or manually in your controllers.</li>
|
| 106 | </ul>
|
admin | 43a823e | 2006-09-27 01:57:10 +0000 | [diff] [blame] | 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 | </div>
|
| 112 | <!-- END CONTENT -->
|
| 113 |
|
| 114 |
|
| 115 | <div id="footer">
|
| 116 | <p>
|
| 117 | Previous Topic: <a href="call_function.html">Custom Function Calls</a>
|
| 118 | ·
|
| 119 | <a href="#top">Top of Page</a> ·
|
| 120 | <a href="../index.html">User Guide Home</a> ·
|
| 121 | Next Topic: <a href="export.html">Database Export Class</a>
|
| 122 | <p>
|
| 123 | <p><a href="http://www.codeigniter.com">Code Igniter</a> · Copyright © 2006 · <a href="http://www.pmachine.com">pMachine, Inc.</a></p>
|
| 124 | </div>
|
| 125 |
|
| 126 | </body>
|
| 127 | </html> |