Plugin Directory

Changeset 989862


Ignore:
Timestamp:
09/15/2014 05:20:39 AM (11 years ago)
Author:
baseapp
Message:

Major updates

Location:
wpbase-cache/trunk/trunk
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • wpbase-cache/trunk/trunk/readme.txt

    r989861 r989862  
    4545
    4646== Changelog ==
     47= 1.0.1 =
     48Major bug fixes
    4749
    4850= 1.0.0 =
  • wpbase-cache/trunk/trunk/wpbase-cache-admin.php

    r989861 r989862  
    4545        );
    4646
    47         add_settings_field(
    48             'wpbase_cache_options_db_cache',
    49             'Enable DB Cache',
    50             array($this, 'db_cache_input'),
    51             'wpbasecache',
    52             'wpbase_cache_section'
    53         );
     47     
    5448
    5549        add_settings_field(
     
    5751            'Enable Varnish Cache',
    5852            array($this, 'varnish_cache_input'),
    59             'wpbasecache',
    60             'wpbase_cache_section'
    61         );
    62 
    63         add_settings_field(
    64             'wpbase_cache_options_view_meta',
    65             'Enable View Meta',
    66             array($this, 'view_meta_input'),
    67             'wpbasecache',
    68             'wpbase_cache_section'
    69         );
    70 
    71         add_settings_field(
    72             'wpbase_cache_options_action_key',
    73             'Action and key pairs',
    74             array($this, 'action_key_input'),
    7553            'wpbasecache',
    7654            'wpbase_cache_section'
     
    8361    }
    8462
    85     public function db_cache_input() {
    86         $options = get_option('wpbase_cache_options');
    87 
    88         $checked = checked(1, $options['db_cache'], FALSE);
    89         echo "<input id='wpbase_cache_db_cache' name='wpbase_cache_options[db_cache]' type='checkbox' value='1' $checked />";
    90     }
    91 
     63   
    9264    public function varnish_cache_input() {
    9365        $options = get_option('wpbase_cache_options');
     
    9971            echo "<input id='wpbase_cache_varnish_cache' disabled='disabled' name='wpbase_cache_options[varnish_cache]' type='checkbox' value='1' $checked />";
    10072        }
    101     }
    102 
    103     public function view_meta_input() {
    104         $options = get_option('wpbase_cache_options');
    105 
    106         $view_meta = $options['view_meta'];
    107         echo "<input id='wpbase_cache_view_meta' name='wpbase_cache_options[view_meta]' type='text' value='$view_meta' />";
    108         echo "<p class='description'>Mostly view counts are handeld by themes and you have to know which postmeta key is used to store view count of each post.<br />Fill in value of that postmeta key here.</p>";
    109     }
    110 
    111     public function action_key_input() {
    112         $options = get_option('wpbase_cache_options');
    113 
    114         $action_key = $options['action_key'];
    115         echo "<textarea id='wpbase_cache_action_key' name='wpbase_cache_options[action_key]' rows='3' cols='20' >$action_key</textarea>";
    116         echo "<p class='description'>Fill in the comma seperated values of action name and post id key for flushing post with the given id on that action.<br />For using multiple action,key pair write them one on each line for example - <br />postratings,pid<br />myaction,mypostid<br />First one is the setting value for famous wp-postrating plugin and second one is a dummy entry</p>";
    11773    }
    11874
     
    14197                });
    14298            });
    143 
    144             $('#wpbase_cache_varnish_cache').change(function(){
    145                 if($(this).is(':checked'))
    146                     $('#wpbase_cache_view_meta').parent().parent().show();
    147                 else
    148                     $('#wpbase_cache_view_meta').parent().parent().hide();
    149             });
    150 
    151             if($('#wpbase_cache_varnish_cache').is(':checked'))
    152                 $('#wpbase_cache_view_meta').parent().parent().show();
    153             else
    154                 $('#wpbase_cache_view_meta').parent().parent().hide();
    15599        });
    156100        </script>
     
    174118
    175119    public function update_options($oldvalue, $newvalue) {
    176         // disable/enable db_cache if needed
    177         if($oldvalue['db_cache'] !== $newvalue['db_cache']){
    178             global $wpbase_cache;
    179             if($newvalue['db_cache'] == '1'){
    180                 $wpbase_cache->activate_db_cache();
    181             } else {
    182                 $wpbase_cache->deactivate_db_cache();
    183             }
    184         }
     120     
    185121    }
    186122
  • wpbase-cache/trunk/trunk/wpbase-cache.php

    r989861 r989862  
    33Plugin Name: WPBase-Cache
    44Plugin URI: https://github.com/baseapp/wpbase-cache
    5 Description: A wordpress plugin for using all caches on varnish, nging, php-fpm stack with php-apc. This plugin includes db-cache-reloaded-fix for dbcache.
    6 Version: 1.0.0
     5Description: A wordpress plugin for using all caches on varnish, nginx, php-fpm stack with php-apc. This plugin includes db-cache-reloaded-fix for dbcache.
     6Version: 1.0.1
    77Author: Tarun Bansal
    88Author URI: http://blog.wpoven.com
     
    3232
    3333    public $wp_db_cache_reloaded = null;
    34     private $action_keys = array();
    35     private $view_meta = "";
    3634
    3735    public function __construct() {
     
    5250    public function activate() {
    5351        $options = array(
    54             'db_cache' => '1',
     52            'db_cache' => '0',
    5553            'varnish_cache' => '1',
    5654            //'reject_url' => '',
     
    6159
    6260        // activate and enable db-cache-reloaded-fix
    63         $this->activate_db_cache();
     61       // $this->activate_db_cache();
    6462    }
    6563
    6664    public function deactivate() {
    67         $this->deactivate_db_cache();
    68         delete_option('wpbase_cache_options');
     65        //$this->deactivate_db_cache();
     66         $options = array(
     67            'db_cache' => '0',
     68            'varnish_cache' => '0',
     69            //'reject_url' => '',
     70            //'reject_cookie' => '',
     71        );
     72
     73        update_option('wpbase_cache_options', $options);
     74        //delete_option('wpbase_cache_options');
    6975    }
    7076
    7177    public function activate_db_cache() {
    72         require_once(WPBASE_CACHE_INC_DIR.'/db-cache-reloaded-fix/db-cache-reloaded.php');
     78    /*    require_once(WPBASE_CACHE_INC_DIR.'/db-cache-reloaded-fix/db-cache-reloaded.php');
    7379        $this->wp_db_cache_reloaded = new DBCacheReloaded();
    7480        $options = array(
     
    7985            'save' => 1
    8086        );
    81         $this->wp_db_cache_reloaded->options_page($options);
     87        $this->wp_db_cache_reloaded->options_page($options);*/
    8288    }
    8389
    8490    public function deactivate_db_cache() {
    85         if($this->wp_db_cache_reloaded != null){
     91      /*  if($this->wp_db_cache_reloaded != null){
    8692            $this->wp_db_cache_reloaded->dbcr_uninstall();
    87         }
     93        }*/
    8894    }
    8995
     
    9399        require_once(WPBASE_CACHE_INC_DIR.'/nginx-compatibility/nginx-compatibility.php');
    94100
    95         if(isset($options['db_cache']) && $options['db_cache'] == '1'){
     101    /*    if(isset($options['db_cache']) && $options['db_cache'] == '1'){
    96102            require_once(WPBASE_CACHE_INC_DIR.'/db-cache-reloaded-fix/db-cache-reloaded.php');
    97103            $this->wp_db_cache_reloaded = new DBCacheReloaded();
    98         }
     104        }*/
    99105
    100106        if(!isset($options['varnish_cache']) || $options['varnish_cache'] != '1'){
    101107            add_action('init', array($this, 'set_cookie'));
    102         } else {
    103             if(isset($options['view_meta']) && !empty($options['view_meta']) && !is_admin()){
    104                 $this->view_meta = $options['view_meta'];
    105                 add_action('wp_footer', array($this, 'view_count_script_footer'));
    106             }
    107 
    108             $action_keys = explode("\n", $options['action_key']);
    109             foreach ($action_keys as $action_key) {
    110                 $action_key = explode(",", $action_key);
    111                 if(count($action_key) == 2) {
    112                     $action = $action_key[0];
    113                     $key = $action_key[1];
    114                     $this->action_keys[$action] = $key;
    115                     add_action('wp_ajax_' . $action, array($this, 'flush_action_key'),9);
    116                     add_action('wp_ajax_nopriv_' . $action, array($this, 'flush_action_key'),9);
    117                 }
    118             }
    119108        }
    120109    }
     
    128117    public function add_flush_actions(){
    129118        add_action('switch_theme', array($this, 'flush_all_cache'));
    130         add_action('publish_post', array($this, 'flush_post'));
    131         add_action('edit_post', array($this, 'flush_post'));
    132         add_action('save_post', array($this, 'flush_post'));
    133         add_action('wp_trash_post', array($this, 'flush_post'));
    134         add_action('delete_post', array($this, 'flush_post'));
    135         add_action('trackback_post', array($this, 'flush_comment'));
    136         add_action('pingback_post', array($this, 'flush_comment'));
    137         add_action('comment_post', array($this, 'flush_comment'));
    138         add_action('edit_comment', array($this, 'flush_comment'));
    139         add_action('wp_set_comment_status', array($this, 'flush_comment'));
    140         add_action('delete_comment', array($this, 'flush_comment'));
    141     }
    142 
    143     public function flush_action_key() {
    144         $action = $_REQUEST['action'];
    145         $key = $this->action_keys[$action];
    146 
    147         $post_id = intval($_REQUEST[$key]);
    148         $this->flush_post($post_id);
    149     }
    150 
    151     public function flush_post($post_id) {
    152         $url = get_permalink($post_id);
    153 
    154         $this->flush_varnish_cache($url);
    155     }
    156 
    157     public function flush_comment($comment_id) {
    158         $comment = get_comment($comment_id);
    159         $post_id = $comment->comment_post_ID;
    160 
    161         $this->flush_post($post_id);
     119        add_action('publish_phone', array($this, 'flush_all_cache'));
     120        add_action('publish_post', array($this, 'flush_all_cache'));
     121        add_action('edit_post', array($this, 'flush_all_cache'));
     122        add_action('save_post', array($this, 'flush_all_cache'));
     123        add_action('wp_trash_post', array($this, 'flush_all_cache'));
     124        add_action('delete_post', array($this, 'flush_all_cache'));
     125        add_action('trackback_post', array($this, 'flush_all_cache'));
     126        add_action('pingback_postt', array($this, 'flush_all_cache'));
     127        add_action('comment_post', array($this, 'flush_all_cache'));
     128        add_action('edit_comment', array($this, 'flush_all_cache'));
     129        add_action('wp_set_comment_status', array($this, 'flush_all_cache'));
     130        add_action('delete_comment', array($this, 'flush_all_cache'));
     131        add_action('comment_cookie_lifetime', array($this, 'flush_all_cache'));
     132        add_action('wp_update_nav_menu', array($this, 'flush_all_cache'));
     133        add_action('edit_user_profile_update', array($this, 'flush_all_cache'));
    162134    }
    163135
     
    167139        $this->flush_varnish_cache($url);
    168140
    169         if($this->wp_db_cache_reloaded != null){
     141       /* if($this->wp_db_cache_reloaded != null){
    170142            $this->wp_db_cache_reloaded->dbcr_clear();
    171         }
     143        }*/
    172144    }
    173145
    174146    public function flush_varnish_cache($url) {
    175147        if(!(defined('WPBASE_CACHE_SANDBOX') && WPBASE_CACHE_SANDBOX)) {
     148            //echo $url;
    176149            wp_remote_request($url, array('method' => 'PURGE'));
    177150        }
    178151    }
    179 
    180     function view_count_script_footer() {
    181         $single = is_single();
    182         if($single == 1) {
    183             $post_id = get_the_ID();
    184             $site_url = get_option("siteurl");
    185     ?>
    186             <script type="text/javascript">
    187                 var data = {
    188                     post_id : "<?php echo $post_id; ?>",
    189                     view_meta : "<?php echo $this->view_meta; ?>"
    190                 };
    191                 var url = "<?php echo $site_url; ?>/wp-content/plugins/wpbase-cache/views.php";
    192                 $.post(url, data, function(data){});
    193             </script>
    194     <?php } }
    195152}
    196153
    197154$wpbase_cache = new WPBase_Cache();
     155//------------------- wpbase-cache update ------------------
     156
     157$cache_options = get_option('wpbase_cache_options');
     158
     159if(!isset($cache_options['varnish_cache']) || $cache_options['varnish_cache'] != '1'){
     160    $site = site_url();
     161    //global $wpbase_cache;
     162    $wpbase_cache->flush_varnish_cache($site);
     163}
Note: See TracChangeset for help on using the changeset viewer.