_db =& $frontend->db; $this->_context =& $frontend->context; $this->validity = $validity; $this->gc_probability = $gc_probability; $this->_table = $frontend->tables_prefix . '_cache'; $this->_valid = date('Y-m-d H:i:s', (time() - $this->validity)); $this->id = md5($_SERVER['REQUEST_URI']); if ($_SERVER['REQUEST_METHOD'] != 'GET' || strpos($_SERVER['REQUEST_URI'], '?') !== false) { $this->active = false; return; } $wpcookie = 'wordpressuser_' . md5($frontend->options['wp_url']); foreach (array_keys($_COOKIE) as $k) { if ($k == 'lp_identity' || $k == $wpcookie) { $this->active = false; return; } } $this->_id = $this->id; // check the last modified date for the context $consider_comments = false; if (empty($this->_context['reqtype'])) $consider_comments = true; // any context where we don't show comments? $lastmod = $frontend->getLastModified($consider_comments); // try to respond to a conditional request $frontend->doConditionalGet($lastmod); $this->_lastmod = date('Y-m-d H:i:s', $lastmod); $r = rand(0, $this->gc_probability); if ($r == 0) $this->garbageCollect(); } function getCache($id=null) { $id = (is_null($id) ? $this->_id : $id); if (is_null($id)) return; $db =& $this->_db; $q = "select content from " . $this->_table . " where " . " hash='" . $this->_id . "' " . " and tstamp >= '" . $this->_valid . "' " . " and tstamp > '" . $this->_lastmod . "' " . " order by tstamp desc limit 1"; $db->query($q); if ($db->count == 0) return; return stripslashes($db->get('content')) . ''; } function setCache(&$content, $id=null) { $id = (is_null($id) ? $this->_id : $id); if (is_null($id)) return; $this->_db->query( "insert into " . $this->_table . " VALUES (" . "NULL, " . "'" . $this->_id . "', " . "now(), " . "'" . addslashes($content) . "')"); } function garbageCollect() { $this->_db->query("delete from " . $this->_table . " where tstamp < '" . $this->_valid . "'"); } } ?>