$value) { $this->$name = $value; } $this->crt_name = $this->prefix . '-cache_retain_time'; // 0 is an acceptable param, so we can't just do a boolean check $this->retain_time = get_option($this->crt_name); } function initialize_options() { $this->settings->add_section(array( 'name' => 'Cache Settings', 'description' => "

Your cache directory can be found at: ". $this->path."

", 'start_collapsed' => true ) ); $this->settings->add_item( 'Cache Settings', 'Enable Caching', 'cache_enable', 'checkbox' ); $this->settings->add_item('Cache Settings', 'Retain Time', 'cache_retain_time', 'custom', false, null, "" ); } function load($filename) { $cache_file = $this->path . '/' . $filename; if (!$this->enabled || !file_exists($cache_file) || ((time() - filemtime($cache_file)) >= $this->retain_time) ) { return false; } if (file_exists($cache_file)) { $contents = file_get_contents($cache_file); return unserialize($contents); } return false; } function save($filename, $data) { $cache_file = $this->path . '/' . $filename; if ( !$this->enabled || (file_exists($cache_file) && ((time() - filemtime($cache_file)) >= $this->retain_time) ) ){ return false; } return file_put_contents($cache_file, serialize($data)); } function check_cache() { if ( isset($this->enabled)) return; $is_cachable = false; if (get_option($this->prefix.'-cache_enable')) { if (!file_exists($this->path)) { if (isset($this->notifications)) { $this->notifications->add_notice( 2, "You do not have a cache directory
If you would like to implement caching, please create the cache directory: " . $this->path . "", "options-general.php?page={$this->prefix}-options#cache_settings" ); } } else if (!is_writable($this->path)) { if (isset($this->notifications)) { $this->notifications->add_notice(2, "Your cache directory is not writable
If you would like to implement caching, please change the permissions on the cache directory: " . $this->path . "", "options-general.php?page={$this->prefix}-options#cache_settings" ); } } else { $is_cachable = true; // looks like we can cache stuff } } $this->enabled = $is_cachable; return (isset($notices)) ? $notices : false; } } ?>