/**
* Table Definition for avatar
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Avatar extends DB_DataObject
+class Avatar extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Avatar',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Avatar',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for confirm_address
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Confirm_address extends DB_DataObject
+class Confirm_address extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Confirm_address',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Confirm_address',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for consumer
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Consumer extends DB_DataObject
+class Consumer extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Consumer',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Consumer',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for fave
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Fave extends DB_DataObject
+class Fave extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Fave',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Fave',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for foreign_link
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Foreign_link extends DB_DataObject
+class Foreign_link extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Foreign_link',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Foreign_link',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for foreign_service
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Foreign_service extends DB_DataObject
+class Foreign_service extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Foreign_service',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Foreign_service',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for foreign_subscription
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Foreign_subscription extends DB_DataObject
+class Foreign_subscription extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $created; // datetime() not_null
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Foreign_subscription',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Foreign_subscription',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for foreign_user
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Foreign_user extends DB_DataObject
+class Foreign_user extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Foreign_user',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Foreign_user',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for invitation
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Invitation extends DB_DataObject
+class Invitation extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $created; // datetime() not_null
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Invitation',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Invitation',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
--- /dev/null
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+if (!defined('LACONICA')) { exit(1); }
+
+require_once 'classes/Memcached_DataObject.php';
+
+class Memcached_DataObject extends DB_DataObject
+{
+ static function &staticGet($cls, $k, $v=NULL) {
+ $i = $this->getcached($cls, $k, $v);
+ if (!is_null($i)) {
+ return $i;
+ } else {
+ $i = parent::staticGet($k, $v);
+ if (!is_null($i)) {
+ $i->encache();
+ }
+ return $i;
+ }
+ }
+
+ function insert() {
+ $result = parent::insert();
+ if ($result) {
+ $this->encache();
+ }
+ return $result;
+ }
+
+ function update($orig=NULL) {
+ if (!is_null($orig)) {
+ $orig->decache(); # might be different keys
+ }
+ $result = parent::update($orig);
+ if ($result) {
+ $this->encache();
+ }
+ }
+
+ function delete() {
+ $this->decache(); # while we still have the values!
+ return parent::delete();
+ }
+
+ static function memcache() {
+ if (!common_config('memcached', 'enabled')) {
+ return NULL;
+ } else {
+ $cache = new Memcache();
+ $res = $cache->connect(common_config('memcached', 'server'),
+ common_config('memcached', 'port'));
+ return ($res) ? $cache : NULL;
+ }
+ }
+
+ static function cacheKey($cls, $k, $v) {
+ return common_cache_key(strtolower($cls) . ':' .
+ $k . ':' .
+ $v);
+ }
+
+ static function getcached($cls, $k, $v) {
+ $c = Memcached_DataObject::memcache();
+ if (!$c) {
+ return false;
+ } else {
+ return $c->get(Memcached_DataObject::cacheKey($cls, $k, $v));
+ }
+ }
+
+ function keyTypes() {
+ global $_DB_DATAOBJECT;
+ if (!isset($_DB_DATAOBJECT['INI'][$this->_database][$this->__table."__keys"])) {
+ $this->databaseStructure();
+
+ }
+ return $_DB_DATAOBJECT['INI'][$this->_database][$this->__table."__keys"];
+ }
+
+ function encache() {
+ $c = $this->memcache();
+ if (!$c) {
+ return false;
+ } else {
+ $primary = array();
+ $types = ksort($this->keyTypes());
+ foreach ($types as $key => $type) {
+ if ($type == 'K') {
+ $primary[] = $key;
+ } else {
+ $c->set($this->cacheKey($this->tableName(), $key, $this->$key),
+ $this);
+ }
+ }
+ # XXX: figure out what to do with compound pkeys
+ if (count($primary) == 1) {
+ $key = $primary[0];
+ $c->set($this->cacheKey($this->tableName(), $key, $this->$key),
+ $this);
+ }
+ }
+ }
+
+ function decache() {
+ $c = $this->memcache();
+ if (!$c) {
+ return false;
+ } else {
+ $primary = array();
+ $types = ksort($this->keyTypes());
+ foreach ($types as $key => $type) {
+ if ($type == 'K') {
+ $primary[] = $this->$key;
+ } else {
+ $c->delete($this->cacheKey($this->tableName(), $key, $this->$key),
+ $this);
+ }
+ }
+ # XXX: figure out what to do with compound pkeys
+ if (count($primary) == 1) {
+ $key = $primary[0];
+ $c->delete($this->cacheKey($this->tableName(), $key, $this->$key),
+ $this);
+ }
+ }
+ }
+}
/**
* Table Definition for message
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Message extends DB_DataObject
+class Message extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $source; // varchar(32)
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Message',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Message',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for nonce
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Nonce extends DB_DataObject
+class Nonce extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Nonce',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Nonce',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for notice
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Notice extends DB_DataObject
+class Notice extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $source; // varchar(32)
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Notice',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Notice',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for notice_source
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Notice_source extends DB_DataObject
+class Notice_source extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Notice_source',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Notice_source',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for notice_tag
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Notice_tag extends DB_DataObject
+class Notice_tag extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $created; // datetime() not_null
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Notice_tag',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Notice_tag',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for profile
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Profile extends DB_DataObject
+class Profile extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Profile',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Profile',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for queue_item
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Queue_item extends DB_DataObject
+class Queue_item extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $claimed; // datetime()
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Queue_item',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Queue_item',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for remember_me
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Remember_me extends DB_DataObject
+class Remember_me extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Remember_me',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Remember_me',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for remote_profile
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Remote_profile extends DB_DataObject
+class Remote_profile extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Remote_profile',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Remote_profile',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for reply
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Reply extends DB_DataObject
+class Reply extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $replied_id; // int(4)
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Reply',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Reply',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for sms_carrier
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Sms_carrier extends DB_DataObject
+class Sms_carrier extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Sms_carrier',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Sms_carrier',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for subscription
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Subscription extends DB_DataObject
+class Subscription extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Subscription',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Subscription',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for token
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class Token extends DB_DataObject
+class Token extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Token',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Token',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* Table Definition for user
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
require_once 'Validate.php';
require_once(INSTALLDIR.'/lib/noticewrapper.php');
-class User extends DB_DataObject
+class User extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('User',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('User',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
}
$qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
' WHERE id = ' . $this->id;
- return $this->query($qry);
+ $orig->decache();
+ $result = $this->query($qry);
+ if ($result) {
+ $this->encache();
+ }
+ return $result;
}
function allowed_nickname($nickname) {
/**
* Table Definition for user_openid
*/
-require_once 'DB/DataObject.php';
+require_once 'classes/Memcached_DataObject.php';
-class User_openid extends DB_DataObject
+class User_openid extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('User_openid',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('User_openid',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE