Changeset 989862
- Timestamp:
- 09/15/2014 05:20:39 AM (11 years ago)
- Location:
- wpbase-cache/trunk/trunk
- Files:
-
- 1 deleted
- 3 edited
-
inc/db-cache-reloaded-fix (deleted)
-
readme.txt (modified) (1 diff)
-
wpbase-cache-admin.php (modified) (6 diffs)
-
wpbase-cache.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wpbase-cache/trunk/trunk/readme.txt
r989861 r989862 45 45 46 46 == Changelog == 47 = 1.0.1 = 48 Major bug fixes 47 49 48 50 = 1.0.0 = -
wpbase-cache/trunk/trunk/wpbase-cache-admin.php
r989861 r989862 45 45 ); 46 46 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 54 48 55 49 add_settings_field( … … 57 51 'Enable Varnish Cache', 58 52 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'),75 53 'wpbasecache', 76 54 'wpbase_cache_section' … … 83 61 } 84 62 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 92 64 public function varnish_cache_input() { 93 65 $options = get_option('wpbase_cache_options'); … … 99 71 echo "<input id='wpbase_cache_varnish_cache' disabled='disabled' name='wpbase_cache_options[varnish_cache]' type='checkbox' value='1' $checked />"; 100 72 } 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>";117 73 } 118 74 … … 141 97 }); 142 98 }); 143 144 $('#wpbase_cache_varnish_cache').change(function(){145 if($(this).is(':checked'))146 $('#wpbase_cache_view_meta').parent().parent().show();147 else148 $('#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 else154 $('#wpbase_cache_view_meta').parent().parent().hide();155 99 }); 156 100 </script> … … 174 118 175 119 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 185 121 } 186 122 -
wpbase-cache/trunk/trunk/wpbase-cache.php
r989861 r989862 3 3 Plugin Name: WPBase-Cache 4 4 Plugin URI: https://github.com/baseapp/wpbase-cache 5 Description: A wordpress plugin for using all caches on varnish, ngin g, php-fpm stack with php-apc. This plugin includes db-cache-reloaded-fix for dbcache.6 Version: 1.0. 05 Description: 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. 6 Version: 1.0.1 7 7 Author: Tarun Bansal 8 8 Author URI: http://blog.wpoven.com … … 32 32 33 33 public $wp_db_cache_reloaded = null; 34 private $action_keys = array();35 private $view_meta = "";36 34 37 35 public function __construct() { … … 52 50 public function activate() { 53 51 $options = array( 54 'db_cache' => ' 1',52 'db_cache' => '0', 55 53 'varnish_cache' => '1', 56 54 //'reject_url' => '', … … 61 59 62 60 // activate and enable db-cache-reloaded-fix 63 $this->activate_db_cache();61 // $this->activate_db_cache(); 64 62 } 65 63 66 64 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'); 69 75 } 70 76 71 77 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'); 73 79 $this->wp_db_cache_reloaded = new DBCacheReloaded(); 74 80 $options = array( … … 79 85 'save' => 1 80 86 ); 81 $this->wp_db_cache_reloaded->options_page($options); 87 $this->wp_db_cache_reloaded->options_page($options);*/ 82 88 } 83 89 84 90 public function deactivate_db_cache() { 85 if($this->wp_db_cache_reloaded != null){91 /* if($this->wp_db_cache_reloaded != null){ 86 92 $this->wp_db_cache_reloaded->dbcr_uninstall(); 87 } 93 }*/ 88 94 } 89 95 … … 93 99 require_once(WPBASE_CACHE_INC_DIR.'/nginx-compatibility/nginx-compatibility.php'); 94 100 95 if(isset($options['db_cache']) && $options['db_cache'] == '1'){101 /* if(isset($options['db_cache']) && $options['db_cache'] == '1'){ 96 102 require_once(WPBASE_CACHE_INC_DIR.'/db-cache-reloaded-fix/db-cache-reloaded.php'); 97 103 $this->wp_db_cache_reloaded = new DBCacheReloaded(); 98 } 104 }*/ 99 105 100 106 if(!isset($options['varnish_cache']) || $options['varnish_cache'] != '1'){ 101 107 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 }119 108 } 120 109 } … … 128 117 public function add_flush_actions(){ 129 118 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')); 162 134 } 163 135 … … 167 139 $this->flush_varnish_cache($url); 168 140 169 if($this->wp_db_cache_reloaded != null){141 /* if($this->wp_db_cache_reloaded != null){ 170 142 $this->wp_db_cache_reloaded->dbcr_clear(); 171 } 143 }*/ 172 144 } 173 145 174 146 public function flush_varnish_cache($url) { 175 147 if(!(defined('WPBASE_CACHE_SANDBOX') && WPBASE_CACHE_SANDBOX)) { 148 //echo $url; 176 149 wp_remote_request($url, array('method' => 'PURGE')); 177 150 } 178 151 } 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 } }195 152 } 196 153 197 154 $wpbase_cache = new WPBase_Cache(); 155 //------------------- wpbase-cache update ------------------ 156 157 $cache_options = get_option('wpbase_cache_options'); 158 159 if(!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.