WordPress.org

Forums

WP Super Cache
Do not cache elements (7 posts)

  1. weboperations
    Member
    Posted 1 year ago #

    I see the "DO NOT CACHE PAGE"secret code.

    I built a cache to serve my sidebar content to a "quick-connect app" that I created for mobile clients.

    You can see the app at http://spartabands.org/app

    You will need to shrink down the app to allow for the javascript to redesign the layout and function to a smartphone.

    I am getting the following message now under my "Coming Events"
    panel in the smartphone version of the page.

    "Warning: Cannot modify header information - headers already sent by (output started at /home/spartaba/public_html/app/index.php:5) in /home/spartaba/public_html/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 89"

    I need to understand where I need to install and how to execute the do not cache this page in regards to the error.

    Many thanks for your time.

    http://wordpress.org/plugins/wp-super-cache/

  2. Donncha O Caoimh
    Member
    Plugin Author

    Posted 1 year ago #

    add this at the top of your app/index.php:

    define( 'DONOTCACHEPAGE', 1 );

    That's all you need to stop caching.

  3. weboperations
    Member
    Posted 1 year ago #

    so you are saying
    <?php
    define( 'DONOTCACHEPAGE', 1 );
    ?>
    <!DOCTYPE HTML>

    or am I missing something?

  4. weboperations
    Member
    Posted 1 year ago #

    it still has the error.

  5. weboperations
    Member
    Posted 1 year ago #

    The content of the panel comes from

    <?php
    include "../wp-load.php";
    $myCachedFile = "../wp-content/themes/cyberchimpspro/cache/cache-sidebar.txt";
    if(file_exists($myCachedFile))
    include_once($myCachedFile);
    else
    echo "Cache doesn't exist.";
    ?>

  6. Donncha O Caoimh
    Member
    Plugin Author

    Posted 1 year ago #

    Define DONOTCACHEHOME before your load wp-load.php and see if that helps?

    Are you sure there's not an empty space before the opening PHP tag?

  7. weboperations
    Member
    Posted 1 year ago #

    Positive-

    <?php
    define( 'DONOTCACHEPAGE', 1 );
    ?>
    <!DOCTYPE HTML>
    <html>
    <head>

    from line 1.

    I am wondering if it is a functional issue.
    I use the following code in the function.php file to cache the sidebar to a text file that is refreshed by a timed expire. Perhaps I need to rename a variable?

    // add sidebar function

    function cache($task, $cacheFile, $cacheTime = 600){
    global $cache;

    // Configure files and directories:
    $cacheDir = TEMPLATEPATH."/cache";
    $cacheFileName = $cacheDir."/cache-$cacheFile.txt";
    $cacheLogFile = $cacheDir."/cache-log.txt";

    // Make cache directory if it doesn't exist
    if(!is_dir($cacheDir)) mkdir($cacheDir, 0755);

    // Make a log of the cache files with their current status
    if(file_exists($cacheLogFile))
    $cacheLog = unserialize(file_get_contents($cacheLogFile));
    else
    $cacheLog = array();

    if($task == 'start'){
    // If cache exists, is less than 6 hours old and is not in deletion queue, keep it - otherwise rebuild cache
    if(file_exists($cacheFileName) && (time() - filemtime($cacheFileName)) < $cacheTime && $cacheLog[$cacheFile] == 1){
    $cache = false;
    } else {
    $cache = true;
    ob_start();
    }
    }elseif($task == 'end' && $cache){
    // If caching, save file contents and update log
    file_put_contents($cacheFileName,ob_get_contents());
    ob_end_flush();
    $cacheLog[$cacheFile] = 1;
    file_put_contents($cacheLogFile,serialize($cacheLog));
    }elseif($task == 'purge'){
    // Set cache to delete and update log
    $cacheLog[$cacheFile] = 0;
    file_put_contents($cacheLogFile,serialize($cacheLog));
    }

    }
    function cache_purge(){
    $cacheDir = TEMPLATEPATH."/cache";
    $cacheLogFile = $cacheDir."/cache-log.txt";
    if(file_exists($cacheLogFile))
    $cacheLog = unserialize(file_get_contents($cacheLogFile));
    else
    $cacheLog = array();
    foreach($cacheLog as $key=>$value)
    $cacheLog[$key] = 0;
    file_put_contents($cacheLogFile,serialize($cacheLog));
    add_action('switch_theme','cache_purge', 10);
    add_action('publish_post','cache_purge', 10);
    add_filter('widget_update_callback','cache_purge', 10);
    }

    This is the file that the cache is pulled from called sidebar-right.php

    <?php
    cache('start', 'sidebar');
    /**
    * Sidebar Right Template
    *
    * Please do not edit this file. This file is part of the Cyber Chimps Framework and all modifications
    * should be made in a child theme.
    *
    * @category CyberChimps Framework
    * @package Framework
    * @since 1.0
    * @author CyberChimps
    * @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
    * @link http://www.cyberchimps.com/
    */
    ?>

    <div id="secondary" <?php cyberchimps_filter_sidebar_right_class(); ?>>

    <?php do_action( 'cyberchimps_before_sidebar' ); ?>

    <div id="sidebar">
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar( 'sidebar-right' ) ) : ?>

    <div class="widget-container">
    <h3 class="widget-title"><?php _e('Pages', 'cyberchimps' ); ?></h3>

      <?php wp_list_pages('title_li=' ); ?>

    </div>

    <div class="widget-container">
    <h3 class="widget-title"><?php _e( 'Archives', 'cyberchimps' ); ?></h3>

      <?php wp_get_archives('type=monthly'); ?>

    </div>

    <div class="widget-container">
    <h3 class="widget-title"><?php _e('Categories', 'cyberchimps' ); ?></h3>

      <?php wp_list_categories('show_count=1&title_li='); ?>

    </div>

    <div class="widget-container">
    <h3 class="widget-title"><?php _e('WordPress', 'cyberchimps' ); ?></h3>

    </div>

    <div class="widget-container">
    <h3 class="widget-title"><?php _e('Subscribe', 'cyberchimps' ); ?></h3>

    </div>

    <?php endif; ?>
    </div><!-- #sidebar -->

    <?php do_action( 'cyberchimps_after_sidebar' ); ?>

    </div><!-- #secondary .widget-area .span3 -->
    <?php cache('end', 'sidebar'); ?>

    It simply creates a text cache that I use to clone the calendar into the quick access app that I created in bootstrap 3.0 .

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP Super Cache
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic