LightPress Cache

Enable the cache only if you really need it, as it may make things worse for your blog and your service provider. Similarly to other cache engines, this cache works by storing a copy of each page in the filesystem, with an additional copy for each identified user (eg having a WordPress or LightPress cookie set). The stored pages expire after a certain amount of time (validity set below), but they are phisically removed from the filesystem after expiration only when the garbage collector runs (gc_probability set below).

This means that if you have a high traffic blog, lots of posts, and many identified users (people who at some time have posted a comment on your blog), you will end up with lots of cache files, most of which will be only marginally useful. Your blog will be slower for most users, the filesystem will be full of unneeded junk, and your service provider will most likely become mad at you.

A few cases where caching might be useful are when

If you have one of the above situations, try to enable caching (we have made it a manual process so you will not enable it by mistake), set the appropriate inclusions/exclusions (eg in the examples above only include the posts which might get slashdotted, and/or the index page), and monitor your server load and your filesystem usage to see if it really helps. Caching is not yet enabled for feeds as they already use Conditional GET. We will add feeds support in one of the next releases.

basedir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'FileCache.php'); if (is_null($lp_opts->basedir)) { echo '

LightPress configuration not found

please check the folder where you have install LightPress, then set (and save) required options'; } else if (!$ret || !class_exists('LightPressCache')) { // if we ever have more than one cache classes, we will need to change this echo class_exists('LightPressCache') . '

Cache class not found

'; } else { // ugly code following, replace with something more modular $lp_cache_args = get_option('lp_opt_cache_args'); $lp_base_url = parse_url(get_option('lp_opt_url')); if (isset($lp_base_url['path'])) $lp_cache_base_path = $lp_base_url['path'] . '/'; else $lp_cache_base_path = '/'; if (!is_array($lp_cache_args) || !is_object($lp_cache)) { // might already be instantiated by the LP clean-up actions if (!is_array($lp_cache_args)) { $lp_cache_args = array(); $lp_cache_args['base_path'] = $lp_cache_base_path; } else { $lp_cache_args['dir'] = stripslashes($lp_cache_args['dir']); } $lp_cache =& new LightPressCache($lp_cache_args, true); } $lp_opt_cache_actions_enabled = get_option('lp_opt_cache_actions_enabled'); $lp_opt_cache_actions_all_pages = get_option('lp_opt_cache_actions_all_pages'); foreach ($lp_cache->constructor_args as $k) $lp_cache_args[$k] = $lp_cache->$k; if (isset($_POST['lp_action'])) { if (isset($_POST['lp_opt_cache_actions_enabled'])) $lp_opt_cache_actions_enabled = $_POST['lp_opt_cache_actions_enabled']; else $lp_opt_cache_actions_enabled = 0; $lp_opts->updateOption('lp_opt_cache_actions_enabled', $lp_opt_cache_actions_enabled); if (isset($_POST['lp_opt_cache_actions_all_pages'])) $lp_opt_cache_actions_all_pages = $_POST['lp_opt_cache_actions_all_pages']; else $lp_opt_cache_actions_all_pages = 0; $lp_opts->updateOption('lp_opt_cache_actions_all_pages', $lp_opt_cache_actions_all_pages); if (!isset($_POST['lp_cache_arg_track_users'])) $_POST['lp_cache_arg_track_users'] = '0'; $lp_cache_args_modified = false; foreach ($_POST as $k=>$v) { if (strpos($k, 'lp_cache_arg_') === 0) { $lp_cache_args_modified = true; $lp_cache_args[substr($k, 13)] = $v; } } if ($lp_cache_args_modified) { $lp_cache_args['base_path'] = $lp_cache_base_path; $lp_opts->updateOption("lp_opt_cache_args", $lp_cache_args); } $lp_cache_args = get_option('lp_opt_cache_args'); } echo '
'; echo '
'; echo 'Cache Options'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
validity
'; echo 'how long does a cache stay valid, in seconds
gc probability
'; echo 'remove expired cache files once every n non-cached requests
storage folder
'; echo 'where to store cache files
track identified users'; echo '
'; echo 'check this to save a personalized copy for identified users, uncheck to always serve them dynamic content
url check method'; echo ' exclude '; echo ' include
'; echo 'controls the scope of the URL list below: \'exclude\' caches all URLs except those listed below, \'include\' caches only the URLs listed below
URL list
'; echo 'URL paths without a trailing slash to include/exclude separated by spaces, eg /mypath/myblog/post/some-post
'; echo "
\n"; echo '
'; echo 'WP Integration'; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
enable WP filters'; echo '
'; echo 'enable the WP filters that clear the cache on new/modified post, comment, etc.
clear all pages'; echo '
'; echo 'check to let WP filters wipe out all cached pages on a post/comment modification, default is to only remove the post page
'; echo "
\n"; echo '

'; echo ''; echo '

'; echo '
'; echo '
'; echo 'Cache Activation'; echo '
    '; echo '
  1. have the cache storage folder writable by the web server process
    '; echo '' . $lp_cache_args['dir'] . ' '; if (is_dir($lp_cache_args['dir'])) { echo 'exists '; if (is_writable($lp_cache_args['dir'])) echo 'and is writable, ok'; else echo 'but is not writable by the server'; } else { echo 'needs to be created'; } echo '
  2. activate the cache bootstrapping file
    '; $lp_cache_dir = $lp_opts->basedir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR; echo 'create the ' . $lp_cache_dir . 'init.php file. You should update the file whenever you change the url option. Copy and paste the following to the file'; echo '
    ';
        $_url_tokens = parse_url($lp_opts->getOption('url'));
        
        echo htmlentities(' ' . $lp_cache_args['validity'] . ', // seconds
        \'gc_probability\'     => ' . $lp_cache_args['gc_probability'] . ', // one in n+1 chances of doing garbage collection
        \'dir\'                => \'' . $lp_cache_args['dir'] . '\',
        \'track_users\'        => ' . ($lp_cache_args['track_users'] == '1' ? 'true' : 'false') . ',
        \'include_or_exclude\' => \'' . $lp_cache_args['include_or_exclude'] . '\',
        \'url_list\'           => \'' . $lp_cache_args['url_list'] . '\',
        \'base_path\'          => \'' . $lp_cache_base_path . '\');
    
    if ($ret && class_exists(\'LightPressCache\')) {
        // retrieve the cache settings
        $cache =& new LightPressCache($lp_cache_settings);
        $cache->activate();
        if ($cache->serve_pages) {
            $cached_page = $cache->getCache();
            if (!empty($cached_page)) {
                header(\'Content-Size: \' . strlen($cached_page));
                echo $cached_page;
                exit();
            }
        }
    }
    
    ?>');
        echo '
    '; echo '
  3. '; echo '
  4. uncomment the following line in ' . $lp_opts->basedir . DIRECTORY_SEPARATOR . 'config.php
    '; echo '
    ';
        echo '// include_once \'cache/init.php\';';
        echo '
    '; echo '
  5. '; echo '
'; echo "
\n"; } ?>