uw Sat Mar 3 11:05:22 2001 EDT
Modified files:
/php4/pear/Cache/Container phplib.php
Log:
Changes for the new structure / features
Index: php4/pear/Cache/Container/phplib.php
diff -u php4/pear/Cache/Container/phplib.php:1.5
php4/pear/Cache/Container/phplib.php:1.6
--- php4/pear/Cache/Container/phplib.php:1.5 Sat Mar 3 03:46:19 2001
+++ php4/pear/Cache/Container/phplib.php Sat Mar 3 11:05:22 2001
@@ -16,12 +16,12 @@
// | Sebastian Bergmann <[EMAIL PROTECTED]> |
// +----------------------------------------------------------------------+
//
-// $Id: phplib.php,v 1.5 2001/03/03 11:46:19 uw Exp $
+// $Id: phplib.php,v 1.6 2001/03/03 19:05:22 uw Exp $
-require_once '/Cache/Container.php';
+require_once 'Cache/Container.php';
/**
-* Stores cache data into a database table.
+* Stores cache data into a database table using PHPLibs DB abstraction.
*
* WARNING: Other systems might or might not support certain datatypes of
* the tables shown. As far as I know there's no large binary
@@ -37,19 +37,21 @@
* For _MySQL_ you need this DB table:
*
* CREATE TABLE cache (
-* id CHAR(32) NOT NULL DEFAULT '',
-* content BLOB NOT NULL DEFAULT '',
-* expires INT(9) NOT NULL DEFAULT 0,
+* id CHAR(32) NOT NULL DEFAULT '',
+* cachegroup VARCHAR(127) NOT NULL DEFAULT '',
+* cachedata BLOB NOT NULL DEFAULT '',
+* userdata VARCHAR(255) NOT NULL DEFAUL '',
+* expires INT(9) NOT NULL DEFAULT 0,
*
-* changed TIMSTAMP(14) NOT NULL,
+* changed TIMESTAMP(14) NOT NULL,
*
* INDEX (expires),
-* PRIMARY KEY (id)
+* PRIMARY KEY (id, cachegroup)
* )
*
*
* @author Ulf Wendel <[EMAIL PROTECTED]>, Sebastian Bergmann
<[EMAIL PROTECTED]>
-* @version $Id: phplib.php,v 1.5 2001/03/03 11:46:19 uw Exp $
+* @version $Id: phplib.php,v 1.6 2001/03/03 19:05:22 uw Exp $
* @package Cache
* @see save()
*/
@@ -140,17 +142,18 @@
} // end constructor
- function fetch($id) {
+ function fetch($id, $group) {
- $query = sprintf("SELECT expires, content FROM %s WHERE id = '%s'",
+ $query = sprintf("SELECT expires, cachedata, userdata FROM %s WHERE id = '%s'
+AND cachegroup = '%s'",
$this->cache_table,
- $id
+ $id,
+ $group
);
$this->db->query($query);
if (!$this->db->Next_Record())
- return array(NULL, NULL);
+ return array(NULL, NULL, NULL);
- return array($this->db->f("expires"), $this->decode($this->db->f("content")));
+ return array($this->db->f("expires"),
+$this->decode($this->db->f("cachedata")), $this->db->f("userdata"));
} // end func fetch
@@ -161,15 +164,16 @@
* MySQL specific. As MySQL is very popular the method should
* work fine for 95% of you.
*/
- function save($id, $data, $expires = 0) {
+ function save($id, $data, $expires, $group) {
- $this->flushPreload($id);
-
- $query = sprintf("REPLACE INTO %s (content, expires, id) VALUES ('%s', %d,
'%s')",
+ $this->flushPreload($id, $group);
+
+ $query = sprintf("REPLACE INTO %s (cachedata, expires, id, cachegroup) VALUES
+('%s', %d, '%s', '%s')",
$this->cache_table,
$this->encode($data),
($expires) ? $expires + time() : 0,
- $id
+ $id,
+ $group
);
$this->db->query($query);
@@ -177,13 +181,14 @@
} // end func save
- function delete($id) {
+ function delete($id, $group) {
- $this->flushPreload($id);
+ $this->flushPreload($id, $group);
$this->db->query(
- sprintf("DELETE FROM %s WHERE id = '%s'",
+ sprintf("DELETE FROM %s WHERE id = '%s' AND cachegroup =
+'%s'",
$this->cache_table,
- $id
+ $id,
+ $group
)
);
@@ -191,25 +196,32 @@
} // end func delete
- function flush() {
+ function flush($group) {
$this->flushPreload();
- $this->db->query(sprintf("DELETE FROM %s", $this->cache_table));
+
+ if ($group) {
+ $this->db->query(sprintf("DELETE FROM %s WHERE cachegroup = '%s'",
+$this->cache_table, $group));
+ } else {
+ $this->db->query(sprintf("DELETE FROM %s", $this->cache_table));
+ }
+
return $this->db->affected_rows();
} // end func flush
- function idExists($id) {
+ function idExists($id, $group) {
$this->db->query(
- sprintf("SELECT id FROM %s WHERE ID = '%s'",
+ sprintf("SELECT id FROM %s WHERE ID = '%s' AND cachegroup =
+'%s'",
$this->cache_table,
- $id
+ $id,
+ $group
)
);
- return $this->db->nf();
+ return (boolean)$this->db->nf();
} // end func isExists
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]