NoPic eZine
  
Home
Impressum/Imprint
Datenschutz/Policies
 
1.Issue 2006.06/1
 1.1.phpWebSite 1.0.0RC1 released
 1.2.Installing pWS 1.0.0rc1
 1.3.Running thru install
 1.4.First anonymous touch
 1.5.Exploring fallout surface inside
 1.6.Module substitution
 1.7.Directory Tree
 1.8.Database Tables
 1.9.ReadMe summary
   Access.txt
   bbcode.txt
   Cache_Lite.txt
   Categories.txt
   Clipboard.txt
   ControlPanel.txt
   Converting_Modules.txt
   Cookie.txt
   CREDITS.txt
   Database_Class.txt
   DB_Pager.txt
   Demographics.txt
   devdoc.modlayout.txt
   Developer_Rules.txt
   Editor.txt
   Forms.txt
   INSTALL.doc.txt
   Key.txt
   Known_Errors.txt
   Language.txt
   LICENSE.txt
   MiniAdmin.txt
   Mod_Rewrite.txt
   Module_Development.txt
   My_Page.txt
   README.doc.txt
   README.txt
   Related.txt
   Search.txt
   Settings_Class.txt
   SmartTags.txt
   Style_Format.txt
   template.txt
   Theme_Creation.txt
   Using_Javascript.txt
   Version.txt
   WYSIWYG.txt
 1.10.Using module WebPages
 1.11.Using module MenuManager
 1.12.Using webPages Editor
 1.13.Styling and Themes

    en

Cache_Lite.txt

Cache List in phpWebSite
by Matt McNaney
--------------------------

PhpWebSite has a caching class from the Pear library. It is easy to
use but be aware of the following issues:

- If the display is user specific, as in it is only seen by one user,
  caching is probably a waste of resources. Try a cache something that
  is to the benefit of several viewers.

- Be careful caching data that requires a different view depending on
  who is logged in. For example, you may have Edit links available for
  certain users. If you cache the data for a regular user, the
  administrators will not see those links.

- Don't cache individual templates. The template class takes care of that
  automatically. Do cache the results of several templates observing
  the rules above.


Cache in action
----------------------------
Here is how your code might look on a simple application:

$key = 'myModsContent';

$content = PHPWS_Cache::get($key);

if (empty($content)) {
  $content = getContentTheHardWay();

  $lifetime = 86400; // number of seconds until cache refresh
                     // default is set in CACHE_LIFETIME in the
                     // config/core/config.php file

  PHPWS_Cache::save($key, $content, $lifetime);
}
 
Layout::add($content);


Pretty simple.
First, create a 'key' for your content. This should be unique so don't
use something like:

$key = 'stuff';

because there is a chance some other module developer may use it as
well.

Next, check to see a cache has been created already using the 'get'
function. If a cache has not been created or the cache has expired,
you will get NULL back.

Should you get nothing back from the 'get' function, create your
content as normal and then use the 'save' function with the 'key' you
made earlier.

Finally, display the either the cached content or the created content
using Layout.

If you need to clear the cache then use the clearCache function:
PHPWS_Cache::clearCache();

This will clear all the caches for the site so use it sparingly.

    en

Copyright © 2006, VbID Verlagsbüro GmbH
pWS modules dcP, dcT, dc4db, Copyright © 2006, VbID Verlagsbüro GmbH
This Site is powered by phpWebSite © The Web Technology Group, Appalachian State University